eulerAngles Vs. localEulerAngles in Unity
Notes:
transform.eulerAngles Vs. transform.localEulerAngles in Unity:
transform.localEulerAngles:
- stores the rotation of a game object relative to parent coordinate system in the form of Vector3 structure
- is used to set rotation of a game object relative to parent coordinate system
- is used to rotate a game object relative to parent coordinate system
Note: if there is no parent then the world is considered as parent
Local Euler Angles:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CubeController : MonoBehaviour {
public Vector3 currentRotation;
public Vector3 anglesToRotate;
void Start () {
currentRotation = new Vector3 (currentRotation.x % 360f,currentRotation.y % 360f,currentRotation.z %360f);
anglesToRotate = new Vector3 (anglesToRotate.x % 360f,anglesToRotate.y % 360f,anglesToRotate.z %360f);
this.transform.localEulerAngles = currentRotation;
}
void Update () {
currentRotation = currentRotation + anglesToRotate * Time.deltaTime;
currentRotation = new Vector3 (currentRotation.x % 360f,currentRotation.y % 360f,currentRotation.z %360f);
this.transform.localEulerAngles = currentRotation;
}
}