Hi,
I am writing a script to rotate a cylinder and I only want it to turn a set angle then stop. I used the following but it seems to stop at the same point no matter what angle I choose. I tried using Quaternion but I could not get it to rotate the right way around.
Euler approach
using UnityEngine;
using System.Collections;
public class rotateCylinder : MonoBehaviour {
public float totalRotation = 0;
public float rotationAmount = 270f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Mathf.Abs (transform.localRotation.eulerAngles.x) <= rotationAmount) {
Debug.Log (transform.localRotation.eulerAngles.x);
transform.Rotate (0, -Time.deltaTime * 20, 0);
}
}
}
Quaternion.
public float totalRotation = 0;
public float rotationAmount = 20f;
if(Mathf.Abs (totalRotation) < Mathf.Abs (rotationAmount)){
float currentAngle = cube.transform.rotation.eulerAngles.z;
cube.transform.rotation = Quaternion.AngleAxis(currentAngle + (Time.deltaTime * 5), Vector3.forward);
totalRotation += Time.deltaTime * 5;
}