I’m a bit new to unity and c# and I can’t manage to stop a rotation at a certain degree.
using UnityEngine;
using System.Collections;
public class RotateBase : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKey(KeyCode.RightArrow))
transform.Rotate (Vector3.up * 0.5f);
if (Input.GetKey(KeyCode.LeftArrow))
transform.Rotate(Vector3.down * 0.5f);
if (transform.rotation.y > 45)
transform.Rotate (Vector3.up * 0.0f);
}
}
When I press the left and right arrows it rotates all the ways around. I tried stopping the rotation when it hit 45 degrees but I have no clue how to do it.
All I know at the moment is basic C# code so if someone can show me how to make the rotation halt at 45 degrees when I’m pressing the right arrow and 315 degrees when I press the left arrow I would be very greatful. Try to keep it simple if you can please.