I need to rotate a 3D object 90 degrees when the player clicks on it. This is the current script I have attached to my 3D object. Unfortunately nothing happens when I click on the 3D object.
function OnMouseClick () {
transform.rotate(90);
}
I could be wrong but I think that OnMouseDown only applies to GUITextures, so what I suggest is a raycast:
#pragma strict
var range : 50;
var hittag : String = "plane";
function Update(){
//raycast vars
var direction = transform.TransformDirection(Vector3.forward);
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
if(Physics.Raycast(ray, hit, range)){
if(hit.transform.tag == hittag){
hit.transform.rotation = Vector3(0, 90, 0);
//or you can use:
//hit.transform.Rotate untill its reached 90
}
}
}