플레이어와 연결된 NPC가 있지만 플레이어와 일정 거리에있을 때 멈출 수 없습니다. 이 일을 위해 웹상에 아무것도 없기 때문에 이것은 밤새 나를 좌절하게했습니다.플레이어의 특정 거리에서 NPC가 멈추지 않습니다.
서로 충돌하여 충돌합니다. 당신은 그것을 멀리로의 경우에만 이동 코드를 적용 할 필요가
using UnityEngine;
using System.Collections;
public class AI : MonoBehaviour {
public Transform target;
public int moveSpeed = 5;
public int rotationSpeed = 2;
public Transform myTransform;
void Awake()
{
myTransform = transform;
}
void Start()
{
target = GameObject.FindWithTag ("Player").transform;
}
void Update()
{
myTransform.rotation = Quaternion.Slerp (myTransform.rotation, Quaternion.LookRotation (target.position - myTransform.position), rotationSpeed * moveSpeed * Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
}
대상 주변에 타원형 타원을 놓고 적이 트리거 충돌 장치를 통과하면 AI가 움직이지 않도록합니다. 'OnTriggerEnter()'를 사용하십시오. –
답장을 보내 주셔서 감사합니다.하지만이 코드는 아래에 나와있는 코드뿐만 아니라 작동하지 않습니다.이 튜토리얼에 대해 알고 계십니까? Unity에 새로운! –