|
How do you destroy the current GameObject? (the one the script is in)
When using BTW - what is the difference between
(comments are locked)
|
|
Destroy(gameObject) does (should) gt rid of attached gameobject From a diff object you could say Destroy(gameObject.FindWithTag("tag")); Or something like that. If you have just 1 prefab onscreen, that seems to get rid of all instances though - so that you can't call Instantiate on it again from another script
Dec 27 '10 at 04:23 AM
ina
It gets rid of a single instance, the one the script is attached to (it's actually Component.gameObject in the base class of your script). If all of your objects are dying, you're calling it on different objects
Dec 27 '10 at 04:33 AM
Mike 3
how do you call it on a different object?
Dec 27 '10 at 04:42 AM
ina
(comments are locked)
|
|
Destroy(gameObject) is the correct way to the GameObject your script is attached to.
I'm not sure what you mean by 'on screen'. Prefabs do not exist inside the scene, they are in the project. You should not be destroying Prefabs.
GameObject is a class. gameObject is a property you can call on a MonoBehaviour to the the GameObject instance that Monobehaviour instance is attached to. this is the instance of the class the code is in. okay... do you need a prefab in the scene to instantiate it?
Dec 27 '10 at 06:23 PM
ina
(comments are locked)
|
|
Have you tried: Destroy(this.gameObject);
(comments are locked)
|
|
this gameobject is nothing but in which gameobject you have placed that script...if you use Destroy(this.gameObject); it'll destroy the gameobject in which you have placed the script.... Destroy(gameObject)- it'll destroy particular gameobject what you have specified. try to store instantiated gameobject name as "clone" and destroy that clone object using Destroy(clone); it'll destroy all objects from origin. that only works if you have one instantiated objects - what if you have more than one
Dec 27 '10 at 07:07 AM
ina
actulally are you creating multiple objects in a same time?? can you give more explain about your concept? and what you're looking for??
Dec 27 '10 at 07:17 AM
sriram90
or you want to destroy objects one by one using time?
Dec 27 '10 at 07:18 AM
sriram90
why cant you try array....store that into "clone[i]" and Destroy(clone[i]); if you want delete all instantiated prefabs....
Dec 27 '10 at 07:40 AM
sriram90
okay so loop through the entire array - no way to just set
Dec 27 '10 at 06:24 PM
ina
(comments are locked)
|
|
once you have destroyed it how can you make it respawn in for instance i have a crosshair that when you press the button to aim the crosshairs are destroyed but how do i get them to come back when you get that button up? This unreadable punctuationless sentence is a comment, not an answer.
Jan 07 at 08:32 PM
Loius
(comments are locked)
|
1 2 next page »

GameObject is the GameObject class, gameObject is a property which retrieves the GameObject attached to the script, this is an instance of the script
This question is probably better broken down into different topics... http://answers.unity3d.com/questions/33473/destroy-the-first-instanced-prefab-while-still-being-able-to-generate-more-prefab and http://answers.unity3d.com/questions/33474/difference-between-gameobject-and-gameobject-and-a-scene-item-named-gameobject
huh.. why the downvote