- Home /
Answer by yeoldesnake 1 · Oct 20, 2011 at 04:26 PM
If you have a DontDestroyOnLoad on the FPC , you are preventing it from getting destroyed not only when you load the second level , but the first as well. So if the first level already has an FPC , the other FPC that is set not to destroy itself will be present. You could save the FPC as a prefab and instantiate based on checking if an FPC already exists. Example:
var prefab:GameObject;
var spawn:Transform;
var fpcExists:boolean=false;
function Awake(){
for(var gameObj : GameObject in GameObject.FindObjectsOfType(GameObject))
{
if(gameObj.name == "FirstPersonController"){
fpcExists=true;
}
}
if(fpcExists==false)
Instantiate (prefab, spawn.position, spawn.rotation);
}
Your answer
