- Home /
Question by
RageGolem10 · Mar 16, 2014 at 11:54 PM ·
prefabnavmeshprefabsnavmeshagentrespawn
Respawning Navmesh and Prefabs
So I have a Enemy prefab that uses navmesh and follows my player around. The problem with this is that when I spawn an enemy after 10 seconds it just crashes into a wall and stays there. Here is my code, and it's attached to a immobile object. I have tried to do this without using a prefab and it works, but then I can't find a way to respawn.
private var startTime : float;
public var enemy : Transform;
private var spawnLocation : int;
function Update ()
{
spawnLocation = Random.Range(0,3);
if (startTime == 0)
{
startTime = Time.time;
}
else
{
if ((Time.time - startTime) >= 10)
{
startTime = 0;
if (spawnLocation == 0)
{
Instantiate (enemy, Vector3(724.1563,3.100793,438.2945), Quaternion.identity);
}
else if (spawnLocation == 1)
{
Instantiate (enemy, Vector3(805.3612,3.100793,491.1311), Quaternion.identity);
}
else if (spawnLocation == 2)
{
Instantiate (enemy, Vector3(712.8903,3.100793,518.0007), Quaternion.identity);
}
}
}
}
Comment
Your answer
