How to stop following player when dead
hi i made one of the ennemy's in my game follow the player. But when the player dies i have a error message that says that the ennemy is searching for the player so it cant reload the level
there is my script (its in JavaScript):
var target :Transform;
var minRange:int;
var follow:boolean;
var speed:float;
function Update(){
if(Vector3.Distance(transform.position,target.position)<minRange)
follow=true;
if(follow){
transform.LookAt(target);
transform.Translate(Vector3.forward *speed* Time.deltaTime);}
}
How can i make the ennemy stop following the player when he id dead?
Answer by NitroGain · Apr 04, 2017 at 06:16 PM
When your player dies do you want to reload the level or re-spawn the player because if you want to reload the level there is no need to stop the enemy from following the player, just don't destroy your player once he dies or make the script call a function in another script using something such as:
void Dead() {
Enemy.GetComponent().ReloadScene();
Destroy(gameobject);
}
Check here for more about calling functions from other scripts : https://forum.unity3d.com/threads/calling-function-from-other-scripts-c.57072/
Your answer

Follow this Question
Related Questions
Destroy moving objcts through touch on screen 0 Answers
If Parent gameobject has DontDestroyOnLoad does it apply to its children? 1 Answer
Can't update a public Variable in another script.. 1 Answer
'Enemies' Dissapearing whenever I get closec 1 Answer
Adding experience + animation before destroy enemy. 0 Answers