Just as the ultra-noob question title states. I'm sure there is a simple script, but I can't find it. How can I make my gameobject cube disappear when I click it?
Attach a simple collider and this script to the object. Choose one of the options.
function OnMouseDown () {
gameObject.active = false;
//Destroy(gameObject);
//renderer.enabled = false;
}
Check out this link about raycasting. This will make your object clickable:
http://unity3d.com/support/documentation/ScriptReference/Collider.Raycast.html
You'll then want to enable or disable the renderer if the raycast hits something
Here's the link for that:
http://unity3d.com/support/documentation/ScriptReference/Renderer-enabled.html
Maybe something like this?:
var objToDel : GameObject; <--- But "cube" here
function Update()
{
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (collider.Raycast (ray, hit, 100.0))
{
delta = hit.gameObject.name;
}
if (delta == objToDel.gameObject.name)
{
objToDel.active = false;
}
}
Not quite sure, can't verify, not @ my computer.