Skip to content

Instantly share code, notes, and snippets.

@Narven
Created May 13, 2014 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Narven/0e3c355f5ae675c2a352 to your computer and use it in GitHub Desktop.
Save Narven/0e3c355f5ae675c2a352 to your computer and use it in GitHub Desktop.
Unity 3D C# script for continuous rotation
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