Question by
Thecodemonkey634 · Feb 02, 2020 at 01:56 AM ·
gameobjectunity 2ddestroynot working
I'm having trouble destroying an instantiated object,I'm having trouble destroying an instantiated gameobject.
I want one certain tagged instantiated object to be destroyed upon mouse over and click. I have scrolled through several discussions about this, and maybe I am just being stupid (Probably the case), but I need a fresh set of eyes.
This is what I have:
void Update() { Vector3 Trashpos = new Vector3(Random.Range(-50, 50), Random.Range(-30, 30), -4); transform.rotation = Quaternion.Euler(-37, 0, 0);
if (Input.GetKeyDown("t"))
{
GameObject CurrentTrash = (GameObject)Instantiate(Trash, Trashpos, transform.rotation);
}
}
public void OnMouseOver()
{
if (gameObject.tag == "Trash")
{
if (Input.GetMouseButtonDown(0))
{
GameObject.Destroy(CurrentTrash, 1f);
}
}
}
I don't know what's wrong with this, I'm not getting any errors either. Help?
Comment