- Home /
My Camera resets rotation to 0 on Play
Hello. I have made a simple mouselook script.
In editor view, I have the camera set how I like it (rotation wise). When I press play, it resets all rotations to 0. I need it to start as I have set it in editor. I've even tried hard-setting the rotation values in Start() but they are completely wrong in Play. Here's my script.
public class MouseLook : MonoBehaviour
{
Vector2 rotation;
public float speed = 3;
void Start()
{
}
void Update()
{
rotation.y += Input.GetAxis("Mouse X");
rotation.x += -Input.GetAxis("Mouse Y");
transform.eulerAngles = rotation * speed;
}
}
Answer by highpockets · Mar 07, 2019 at 10:48 PM
I believe the camera is doing exactly what you are asking it in your script. If you are not touching the mouse, than it will be at 0 because your mouse movement is 0 on both axis and the Vector2 rotation is not assigned any values to begin with so it will take on 0,0. So, in the start method you could set rotation.x and rotation.y to the camera x and y Euler angles and that should do it.
Your answer
![](https://koobas.hobune.stream/wayback/20220612193137im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how to check if rotation is past a point? 1 Answer
Mouse look script with no world up axis behaves weirdly 1 Answer
Disable MouseLook for dialogues 2 Answers
Disabling a script in runtime 2 Answers