Hello
I have a cube i want to look at the position where the mouse clicks (using a raycasthit and a plane in front of the camera with no mesh renderer) but only on the x axis…the problem with my code is that the cube will look at the mouse cursor, unless i click behind it, then it doesn’t look.
I’ve tried it by setting the rotation that i DON’T want to move.
var direction : Vector3;
function Update () {
if(Input.GetButtonDown("Shoot2"))
{
var hit : RaycastHit;
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit))
{
direction = (hit.point);
transform.LookAt(direction);
}
}
transform.eulerAngles.y = 90;
transform.eulerAngles.z = 0;
}
Anyone know a way that works? Thanks