Click on object to get its name??

How would I go about to click somewhere on the screen and read the name of the object i clicked on into a variable??

Any help is always appreciated! Thank you! :slight_smile:

var nameOfClickedObject : String = " ";

function Update(){
    if(Input.GetButtonDown("Fire1")){
        var hit : RaycastHit;
        var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if(Physics.Raycast(ray, hit))
            nameOfClickedObject = hit.transform.name;
    }
}

That should do it.

Thanks man! Works like a charm!! :slight_smile: