Created
May 13, 2014 11:59
-
-
Save Narven/0e3c355f5ae675c2a352 to your computer and use it in GitHub Desktop.
Unity 3D C# script for continuous rotation
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; | |
// Continous rotation with some parameters | |
public class Rotation : MonoBehaviour | |
{ | |
public enum RotationAxis | |
{ | |
All, | |
Y, | |
X, | |
Z | |
} | |
public RotationAxis axis; | |
public float speedRot = 0.3f; | |
void Update () | |
{ | |
float rot = Time.deltaTime * speedRot; | |
//Debug.Log("Axis: "+axis); | |
switch( axis ) | |
{ | |
default: | |
case RotationAxis.All: | |
// Debug.Log("Rotating All"); | |
transform.Rotate( new Vector3( rot, rot, rot ) ); | |
break; | |
case RotationAxis.X: | |
//Debug.Log("Rotating X"); | |
transform.Rotate( new Vector3( rot, 0f, 0f ) ); | |
break; | |
case RotationAxis.Y: | |
//Debug.Log("Rotating Y"); | |
transform.Rotate( new Vector3( 0f, rot, 0f ) ); | |
break; | |
case RotationAxis.Z: | |
//Debug.Log("Rotating Z"); | |
transform.Rotate( new Vector3( 0f, 0f, rot ) ); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment