- Home /
Seperate NavMeshAgent for each instance of a prefab?
Hello,
Post #1 so yes I'm a complete newb :)
I've just completed the Survival Shooter tutorial and was wondering about NavMesh and script instancing. I've tinkered with the tutorial scripts and introduced an alt-fire mode where I intended that the shot would do no damage but temporarily stop the hit object from moving.
In the script that I've named scPlayerShoot I set a bool value for the alt fire mode when the player uses it and in the Enemy Movement scripts I do this:
void Update ()
{
if (!scPlayerShoot.bAltFire) {
if (enemyHealth.currentHealth > 0 && playerHealth.currentHealth > 0) {
nav.SetDestination (player.position);
} else {
nav.enabled = false;
}
} else if(enemyHealth.currentHealth > 0){
nav.Stop(); // stop the critter if alt-fire used
}
}
This works fine but (I assume) because the script is shared between the cloned Zombunnies, Zombears etc they all share the same NavAgent and when one stops they all stop.
So, my questions are these: 1) Is there any way to target the clone / instance carrying the script when used in a prefab? 2) Is this shared behaviour somehow unique to the Navmesh agent? (Since health for instance seems to be local to the instanced clone) 3) How to dynamically assign variables when spawning continuously as in the Survival game example or say, from an array?
Many thanks