- Home /
Question by
SRippington · Nov 15, 2012 at 02:33 PM ·
objectmousedisappearmouse click
How to I get an object to disappear when I use the mouse to click on it?
I have this coding...
function Update () { if (Input.GetButtonDown ("Fire1")) { transform.position = Vector3(Input.mousePosition.x, 0, Input.mousePosition.y); } }
This makes the object disappear but if I click anywhere on the scene it disappears. I want to restrict it so it only disappears when I click on the object.
Comment
Best Answer
Answer by Montraydavis · Nov 15, 2012 at 02:34 PM
Add a script with the following code to the object you want to go-away when clicked:
function OnMouseDown () {
gameObject.active = false; //hide
//Destroy(gameObject); //delete
}