- Home /
How can i destroy a game object?
Hey Guys i just want to ask something, how can i destroy a game object but when it is destroyed it still has its scripts attached to it. Basically i am doing this because in my game the player can change is player by clicking on a character. is there anyway i can do that. or the second thing i was thinking is instead of destroying the object i was thinking once the new player re-spawns on the current player the first players mesh and script get turned of and then that activates the other player scripts. Please help me out thank you in advance.
Answer by Tobbe Olsson · Nov 02, 2010 at 04:38 AM
Make a prefab, destroy it when you want and instantiate it when you want? A prefab can contain a hierarchy and scripts.
ya correct ans from Tobbe Olsson, just create a prefab and make instantiate for that, and just destroy that instantiate(clone) or prefab watever you want.
I have done this but my prefab starts to make clones how can i stop this
It seems maybe you need to explain a bit more what you are doing, maybe show the code. A prefab is just an empty container that you can contain everything you want (scripts, geometry, hierarchy, animations). So if your prefab starts making clones it's because you have a script attach to the prefab (and active in the scene) that tells it to create clones. Though I would also read up on the basics of prefabs and what you can do with them.
There are soo many great free Unity tutorials out there that walk you through it and explains the code. That's how I got started!
Thank you i have fixed the problem thanks to you i just noticed that all the scripts that i was adding where on the prefab after changing them everything is now O$$anonymous$$ thank you very $$anonymous$$UCH :)
Your answer
Follow this Question
Related Questions
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
How to Play 3D Sound and Keep Script on Multiple Prefabs after Destroying a gameObject? 0 Answers
Trouble with destroying an instantiated prefab 2 Answers
Create a prefab at same position where its destroyed 3 Answers
Check if object is destroyed on level load, if so instantiate prefab? 1 Answer