Hi! I’m going crazy trying to figure out how to make my player (a simple cube) always look at the cursor. I’ve tried a few things, including various modifications to suggestions in this post.
My basic setup is an isometric game with a cube character. Here is a screenshot of the setup:
My character, the cube, has the ability to move along the X and the Z axis - he will always be locked in the same Y coordinate (sitting on the flat ground). My attempts have mainly been using something similar to this:
void Start()
{
cameraDif = camera.transform.position.y - player.transform.position.y;
}
void Update ()
{
player.transform.LookAt(new Vector3(Input.mousePosition.x, cameraDif, Input.mousePosition.z));
}
Any help would be greatly appreciated! Thanks 
Here’s a quick script I wrote that seems to do the trick. All it does is perform a raycast from the main camera to the mouse cursor and beyond. If the raycast strikes anything you’ve tagged as “Ground,” the cube will then rotate to face towards the point of the hit.
public class CubeScript : MonoBehaviour
{
Ray cameraRay; // The ray that is cast from the camera to the mouse position
RaycastHit cameraRayHit; // The object that the ray hits
void Update ()
{
// Cast a ray from the camera to the mouse cursor
cameraRay = Camera.main.ScreenPointToRay(Input.mousePosition);
// If the ray strikes an object...
if (Physics.Raycast(cameraRay, out cameraRayHit))
{
// ...and if that object is the ground...
if(cameraRayHit.transform.tag=="Ground")
{
// ...make the cube rotate (only on the Y axis) to face the ray hit's position
Vector3 targetPosition = new Vector3(cameraRayHit.point.x, transform.position.y, cameraRayHit.point.z);
transform.LookAt(targetPosition);
}
}
}
}
I’m sure the code to be improved in several ways (like making the rotation occur over time rather than instantly), but this should at least help get you started.
I hope this helps, and best of luck!
try the method they use in the Nightmares tutorial in Unite 2014. you can find the tutorial in youtube in the Unity channel.
I made a tutorial about this, it’s basically the same solution, but I try to explain how it works in the video.
I will leave it here, might help somebody. 