I want to destroy a prefab on a mouseup,
i don’t think my syntax is correct in identifying the prefab.
Here is the script for the button: (the other functions work fine)
function Start () {
}
var prefab : Transform;
function OnMouseDown () {
Instantiate (prefab);
Destroy (gameObject);
}
function OnMouseUp () {
DestroyImmediate (GameObject(“2012(Clone)”),true);
}
How about this- instead of trying to identify the clone by name (which yes, you do have the wrong syntax for), keep a reference to the clone so that even if the name changes, you can still destroy it? Another thing, I don’t think you want to go destroying the local gameObject. If you do that, the OnMouseUp function will never get called.
var prefab : Transform;
private var clone : GameObject;
function OnMouseDown()
{
clone = (GameObject)Instantiate (prefab);
}
function OnMouseUp()
{
Destroy(clone); // don't use DestroyImmediate outside of editor code
}