Why does this work this pops up
![/Users/user/Desktop/Screen Shot 2017-07-17 at 5.40.34 PM.png][1]
public float deathDistance = 0.5f;
public float distanceAway;
public Transform thisObject;
public Transform target;
private NavMeshAgent navComponent;
void Start()
{
target = GameObject.FindGameObjectWithTag("Player").transform;
navComponent = this.gameObject.GetComponent();
}
void Update()
{
float dist = Vector3.Distance(target.position, transform.position);
if(target)
{
navComponent.SetDestination(target.position);
}
else
{
if(target == null)
{
target = this.gameObject.GetComponent();
}
else
{
target = GameObject.FindGameObjectWithTag("Player").transform;
}
}
if (dist <= deathDistance)
{
//KILL PLAYER
}
}
[1]: /storage/temp/97864-screen-shot-2017-07-17-at-54034-pm.png
↧