how to make a gameobject look at the mouse unity code example
Example 1: how to look around with mouse in unity
public class CameraController : MonoBehaviour
{
Vector2 rotation = Vector2.zero;
public float speed = 3;
void Update ()
{
rotation.y += Input.GetAxis("Mouse X");
rotation.x += -Input.GetAxis("Mouse Y");
transform.eulerAngles = (Vector2)rotation * speed;
}
}
Example 2: how to look around with mouse in unity
public class CameraController : MonoBehaviour
{
Vector2 rotation = Vector2.zero;
public float speed = 3;
void Update ()
{
rotation.y += Input.GetAxis("Mouse X");
rotation.x += -Input.GetAxis("Mouse Y");
transform.eulerAngles = (Vector2)rotation * speed;
}
}