I am making a 2d unity game with C#. Right now, I am trying to make the camera rotate and I am using this code:
rotateX = Random.Range (0, 50);
Camera.main.transform.eulerAngles = Vector3(0,0,rotateX);
But every time I try to run the game, it gives me an error. Anybody have tips on how I can (smoothly) rotate the camera from side to side?
You can get rid of errors by changing your code to this:
void Update () {
float rotateX = Random.Range (0, 50);
transform.eulerAngles = new Vector3(0,0,rotateX);
}
And attaching script component containing it to the camera. But then it is rotating randomly all the time.
I'm not sure, from the question, what kind rotation do you want. But you can use for example this
void Update () {
transform.Rotate(Vector3.forward, 10.0f * Time.deltaTime);
}
to rotate the camera smoothly. Just change to first parameter to the axis around what you want to rotate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With