敵ロボットを左ターンさせる
左ターン
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyMove : 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;
switch (tagName)
{
case "Right":
transform.localRotation = Quaternion.Euler(0, transform.eulerAngles.y + 90, 0);
break;
// ★★追加
case "Left":
transform.localRotation = Quaternion.Euler(0, transform.eulerAngles.y + 270, 0);
break;
}
}
}
}
左ターン
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyMove : 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;
switch (tagName)
{
case "Right":
transform.localRotation = Quaternion.Euler(0, transform.eulerAngles.y + 90, 0);
break;
// ★★追加
case "Left":
transform.localRotation = Quaternion.Euler(0, transform.eulerAngles.y + 270, 0);
break;
}
}
}
}
敵ロボットを左ターンさせる