Hi, all,
I am trying to get a camera to follow an instantiated, controlled object. I had great success (thanks Ratamorph) getting my main player object to swap out with another, however, the camera does not continue on with the prefab despite it’s working controls.
I am using the following code on a run of the mill smoothfollow script. Both my current player object and my instantiated prefab both have the tag “Player” selected. Any thoughts?
if (!target)
{
target = GameObject.FindWithTag("Player").transform;
distance = 15.0;
//return;
}
Could there be a disconnect due to Unity stamping (clone) after the prefab instantiation? If so, how does one lose that suffix?
Thanks,
Greg
No, that would only affect the name, not the tag. My guess is that you need to tell the script to follow the new prefab. Unless you’re destroying the old prefab instead of disabling it, “target” will still be true, so the code for “if (!target)” will never run.
–Eric
Thanks, Eric,
Would the above script work if I disabled my first prefab object instead of destroying it? I am using the following script to instantiate and destroy the prefab:
var refabToInstantiate : GameObject;
function OnTriggerEnter(colliderHit : Collider)
{
Instantiate(prefabToInstantiate, transform.position, transform.rotation);
Destroy(colliderHit.gameObject);
Destroy(transform.gameObject);
}
I don’t understand why the camera will not pick up the new instantiated prefab’s tag and move along with it. How would I disable my first prefab instead of destroying it?
Thanks,
Greg
I actually meant that destroying the prefab should work; I thought maybe you were disabling it instead. So I’m not really sure what the issue would be given what you’ve posted here.
–Eric
Thanks, Eric, I’ll just noodle around with it and see what’s up.
Thanks,
Greg