click = delete?

What im trying to get at is I want it so when i click, it will check if anything is there, and if there is, it will delete it.
I don’t want to have it so I have to attach the script to all the objects tho, just the camera i want the script in… how can i do this?

This can be done by using Camera.ScreenPointToRay(), Physics.Raycast(), and Object.Destroy(). (See the docs for details on these functions and examples of how to use them.)

This.
Cast a ray from screen and if it hits something, destroy what it hit.

so it would be like this?

function OnMouseDown()
{
	var ray : Ray = camera.ScreenPointToRay (Input.mousePosition);
	if(Physics.Raycast(ray)){
		Destroy(gameObject); //????? like this?
	}
}

because it doesnt work… :frowning:

nvm i got it

hey plz tel me the way u got it.

becauz i also want to use this function in following way

function OnMouseDown ()
{

var ray : Ray = camera.ScreenPointToRay (Input.mousePosition);
if(Physics.Raycast(ray)){

print(“clicked”);
}

}

above function will give us that ur object is clicked , but i’m having number of cubes in my scene. and i want to check for all of them , are clicked or not?