Hi,
How do I have an object look at the mouse? I tried transform.LookAt(MouseCursor.Arrow) but that threw an error.
Hi,
How do I have an object look at the mouse? I tried transform.LookAt(MouseCursor.Arrow) but that threw an error.
What you want to do is advanced.
Your 3D object can only look a point in 3d space, so you need X, Y and Z position values. Mouse only give you X and Y position on the screen, and those do not correspond to the 3D space.
Try using Camera.ScreenToWorldPoint(), that’ll help you get a 3D position using your cursor’s 2D position.
Here’s the link for that camera function:
Hmmm. The problem is that’s in the camera class, I can’t use that with a gameobject.
What do you mean? Why can’t you use the camera class with a game object?
Also, could you clarify what you mean by ‘look at the mouse’? That could mean any number of things (such as orienting towards the cursor in a top-down 2-d game, or tracking a target in 3-d space as dogzerx described).