For practice, I’m making a game which is like one of those maze games where you rotate the maze itself and direct a ball, avoiding holes. I’ve managed to allow the maze’s rotation to be controlled by the player. However, I can’t figure out how to stop the maze from rotating past 30 degrees.
Here’s my script that controls this:
using UnityEngine;
using System.Collections;
public class MazeController : MonoBehaviour {
public GameObject maze;
// Use this for initialization
void Start ()
{
}
void FixedUpdate ()
{
float rotateEW = Input.GetAxis("Vertical");
float rotateNS = Input.GetAxis("Horizontal");
if (maze.transform.rotation.x < 30.0)
{
maze.transform.Rotate(0.0f, 0.0f, rotateNS);
}
if (maze.transform.rotation.z < 30.0)
{
maze.transform.Rotate(rotateEW, 0.0f, 0.0f);
}
}
}