Created
June 16, 2015 03:14
-
-
Save rutcreate/1cf883cc07a87392e9ac to your computer and use it in GitHub Desktop.
Unity3D: Rotate specific angle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
namespace Opendream { | |
public class ExampleRotate : MonoBehaviour { | |
public Transform m_Transform; | |
public Vector3 angle; | |
private void Update() { | |
if (m_Transform == null) return; | |
UpdateRotationX(); | |
UpdateRotationY(); | |
UpdateRotationZ(); | |
} | |
private void UpdateRotationX() { | |
Quaternion newRotation = Quaternion.AngleAxis(angle.x, Vector3.right); | |
m_Transform.rotation = new Quaternion(newRotation.x, m_Transform.rotation.y, m_Transform.rotation.z, m_Transform.rotation.w); | |
} | |
private void UpdateRotationY() { | |
Quaternion newRotation = Quaternion.AngleAxis(angle.y, Vector3.up); | |
m_Transform.rotation = new Quaternion(m_Transform.rotation.x, newRotation.y, m_Transform.rotation.z, m_Transform.rotation.w); | |
} | |
private void UpdateRotationZ() { | |
Quaternion newRotation = Quaternion.AngleAxis(angle.z, Vector3.back); | |
m_Transform.rotation = new Quaternion(m_Transform.rotation.x, m_Transform.rotation.y, newRotation.z, m_Transform.rotation.w); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment