I think you should add boolean in your GhostScript:
private bool chasingPlayer;
void Start() {
chasingPlayer = true;
// Here will be other things for start
}
void Update() {
if (chasingPlayer) {
// chasing player algorithm
} else {
// going back to base
}
}
public void goBack() {
chasingPlayer = false;
}
After that in your PlayerScript you will write this:
function OnTriggerEnter(ghost:Collider){
if(ghost.gameObject.tag=="Ghosts"){
lives--;
monsters=GameObject.FindGameObjectsWithTag("Ghosts");
for(var monster in monsters){
GhostScript script = monster.GetComponent();
script.goBack();
}
transform.position=Vector3(0,1,-16);
}
}
That how I do.
Trending Articles
More Pages to Explore .....