easy one - how to destroy the object under the mouse..

im using this kind of code…

public var myCamera : Camera;
var hit : RaycastHit;
var rayDistance : float = 100;

function Update () {
	
	var ray = myCamera.ScreenPointToRay (Input.mousePosition);
	
	if (Input.GetMouseButtonDown (0)){	
		if (Physics.Raycast (ray, hit, rayDistance)) {
		
                 INSERT DESTROY OBJECT THAT THE MOUSE HAS CLICKED HERE! 								
					
		}
	}
}

can somebody please point me in the right direction? i need to destroy the object the mouse has clicked…

thanks in advance!

Destroy(hit.transform.gameObject);

Interesting to see someone who’s mastered the raycast but not the object destruction, it’s usually the other way around.
But yes, it’s fairly straight forward:

Destroy(hit.collider.gameObject);

hehe… its not mastered :slight_smile: its copy-pasted :wink: im just begining to learn javascript and what better way to learn then to do it on an actual project! :slight_smile:

Thanks guys for the quick response, this really helps, you probably know this from the top of your head, i spent 30 minutes trying different things and searching wikis and documents and stuff… but its really an easy one :wink:

Create a small script and add it to the object that can be destroyed…

function OnMouseDown () {
Destroy(gameObject);
}