敵ロボットを右ターンさせる
右ターン
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;
}
}
}
}
右ターン
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;
}
}
}
}
敵ロボットを右ターンさせる