So I'm making a 3d fps game. I was using @Brackeys tutorial - https://www.youtube.com/watch?v=xppompv1DBg just to add enemy. I checked my script 2 times, It's the same as in the video, i did all things correctly and got this error. I tried to press Window>Navigation and change some settings but it did not help me.
Maybe this tutorial is not for 3D game, but i think it is. I'll be really thankful if someone will help.
Thanks, here's my script
public float lookRadius = 10f;
Transform target;
NavMeshAgent agent;
// Use this for initialization
void Start () {
target = PlayerMAnager.instance.player.transform;
agent = GetComponent();
}
// Update is called once per frame
void Update () {
float distance = Vector3.Distance(target.position, transform.position);
if (distance <= lookRadius)
{
agent.SetDestination(target.position);
if (distance <= agent.stoppingDistance)
{
FaceTarget();
}
}
}
void FaceTarget()
{
Vector3 direction = (target.position - transform.position).normalized;
Quaternion lookRotation = (Quaternion.LookRotation(new Vector3(direction.x, 0, direction.z)));
transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * 5f);
}
private void OnDrawGizmosSelected()
{
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(transform.position, lookRadius);
}
}
↧