- Home /
i need to destroy prefab clones
u can apply this script to ur camera
#pragma strict
var item1 : GameObject;
var item2 : GameObject;
var item3 : GameObject;
var Item;
var dropcount = 0;
function Update()
{
if(dropcount == 1)
{
Item = item1;
}
if(dropcount == 2)
{
Item = item2;
}
if(dropcount == 3)
{
Item = item3;
}
}
function OnGUI()
{
if(GUI.Button(Rect(250, 250, 100, 50), "Destroy"))
{
Destroy(Item);
}
if(GUI.Button(Rect(250, 200, 100, 50), "Spawn"))
{
Instantiate(Item);
}
if(GUI.Button(Rect(200, 150, 50, 50), "1"))
{
dropcount = 1;
}
if(GUI.Button(Rect(200, 200, 50, 50), "2"))
{
dropcount = 2;
}
if(GUI.Button(Rect(200, 250, 50, 50), "3"))
{
dropcount = 3;
}
}
Answer by valim · Jan 04, 2014 at 01:48 PM
I think you should put that instead of Destroy(Item);
Destroy(GameObject.Find(item.name + " (Clone)"));
Also you can't destroy a prefab so it should give an error :)
ya umm that didnt even work.... heres error- destroy item.js(30,46): BCE0019: 'name' is not a member of 'Object'.
I'm not used to javascript :)
Destroy(GameObject.Find(Item.name + "(Clone)"));
and
var Item : GameObject;
Tested.
nice! it worked do u know if theres a way 2 make it so when i do this part to make it spawn at my players location?
if(GUI.Button(Rect(250, 200, 100, 50), "Spawn"))
{
Instantiate(Item);
}
Your answer
Follow this Question
Related Questions
How do I destroy a Instantiated UI image that is pushed on the Canvas? 2 Answers
How to spawn a 'boss' after all enemies defeated and then kill that 'boss'? 1 Answer
Instantiated object is destroyed in scene, but still logs as existing in console. 1 Answer
Object wont object get destroyed 1 Answer
How to spawn an object continually while floating vertically like a bubble 1 Answer