Unity3D Csharp script for continuous rotation

Just some basic script for continuous rotation in Unity3D, with some simple params.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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;

    }

  }
}
comments powered by Disqus