特殊能力の追加その2(敵を寝返りさせる)

敵をこちらの味方に変換する
using UnityEngine;
public class BotMove : MonoBehaviour
{
public float moveSpeed;
private float maxDis = 0.75f;
private string tagName;
void Update()
{
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
RaycastHit hit;
Ray ray = new Ray(transform.position, transform.forward);
Debug.DrawRay(transform.position, transform.forward * maxDis, Color.red);
if (Physics.Raycast(ray, out hit, maxDis))
{
GameObject target = hit.collider.gameObject;
tagName = target.tag;
if (tagName == "Right")
{
transform.localRotation = Quaternion.Euler(0, transform.eulerAngles.y + 90, 0);
}
else if (tagName == "Left")
{
transform.localRotation = Quaternion.Euler(0, transform.eulerAngles.y + 270, 0);
}
else if (tagName == "Slow")
{
moveSpeed = 1;
}
// ★追加
else if (tagName == "Reverse")
{
transform.localRotation = Quaternion.Euler(0, transform.eulerAngles.y + 180, 0);
// 三項演算子のテクニック
// もしも自分のタグがRedBotだったら、BlueBotに変更する
// もしも自分のタグがRedBotではなかった(BlueBotだった)ならば、RedBotに変更する
this.gameObject.tag = (this.gameObject.tag == "RedBot") ? "BlueBot" : "RedBot";
}
}
}
}



【Unity6版】TowerDX(全 回)
他のコースを見る
敵をこちらの味方に変換する
using UnityEngine;
public class BotMove : MonoBehaviour
{
public float moveSpeed;
private float maxDis = 0.75f;
private string tagName;
void Update()
{
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
RaycastHit hit;
Ray ray = new Ray(transform.position, transform.forward);
Debug.DrawRay(transform.position, transform.forward * maxDis, Color.red);
if (Physics.Raycast(ray, out hit, maxDis))
{
GameObject target = hit.collider.gameObject;
tagName = target.tag;
if (tagName == "Right")
{
transform.localRotation = Quaternion.Euler(0, transform.eulerAngles.y + 90, 0);
}
else if (tagName == "Left")
{
transform.localRotation = Quaternion.Euler(0, transform.eulerAngles.y + 270, 0);
}
else if (tagName == "Slow")
{
moveSpeed = 1;
}
// ★追加
else if (tagName == "Reverse")
{
transform.localRotation = Quaternion.Euler(0, transform.eulerAngles.y + 180, 0);
// 三項演算子のテクニック
// もしも自分のタグがRedBotだったら、BlueBotに変更する
// もしも自分のタグがRedBotではなかった(BlueBotだった)ならば、RedBotに変更する
this.gameObject.tag = (this.gameObject.tag == "RedBot") ? "BlueBot" : "RedBot";
}
}
}
}



特殊能力の追加その2(敵を寝返りさせる)