- Home /
Instantiated Object turning off scripts and audio source?(Solved)
My player object has started to act weirdly and now when I respawn the object (after a death) the instantiated version has some components turned off. In this case its main script and audio source.
picture on left is the game object as seen in edit mode. Picture on right is the prefab as seen in edit mode.
picture on left is the instantiated object during runtime. Pic on right is the prefab during runtime.
the controller script -
public GameObject playerShip;
public Transform respawnPoint;
void OnTriggerEnter (Collider other)
{
if (other.tag == "Bolt")
{
Instantiate(playerExplosion, transform.position, transform.rotation);
Destroy(other.gameObject);
Destroy(gameObject);
Instantiate(playerShip, respawnPoint.transform.position, respawnPoint.transform.rotation);
LivesManager.lives -= 1;
}
Why is the clone turning off its script and audio source ???
Answer by DoTA_KAMIKADzE · Apr 08, 2015 at 05:37 PM
How about switching those 2 lines?:
Destroy(gameObject);
Instantiate(playerShip, respawnPoint.transform.position, respawnPoint.transform.rotation);
To those?:
Instantiate(playerShip, respawnPoint.transform.position, respawnPoint.transform.rotation);
Destroy(gameObject);
Strangely enough I was sure I'd already tried that, guess not.
Anyway, yep that fixed it.
Thanks
:)
Thank you very much, 4 years later this helps very much. Not much hope this late but can you explain why I first have to respawn and then destroy the object? :D
Your answer
Follow this Question
Related Questions
GameObject parenting during runtime 1 Answer
Instantiating scripts with references to prefabs loses the reference. 1 Answer
How can I enable/disable a component of a Clone 1 Answer
Manipulate a gameobject on runtime and clone it with the current shape 0 Answers
Overwriting a prefab in runtime? 1 Answer