Unity3D Csharp scripts for continuous rotation

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

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;

    switch( axis )
    {
      default:
      case RotationAxis.All:
        transform.Rotate( new Vector3( rot, rot, rot ) );
        break;
      case RotationAxis.X:
        transform.Rotate( new Vector3( rot, 0f, 0f ) );
        break;
      case RotationAxis.Y:
        transform.Rotate( new Vector3( 0f, rot, 0f ) );
        break;
      case RotationAxis.Z:
        transform.Rotate( new Vector3( 0f, 0f, rot ) );
        break;
    }
  }
}
Pedro Luz
A personal blog by Pedro Luz about coding, coding, habit building, and a few things more.(Psst... I am open to opportunities.)
Reach out to me on your favorite social :)© 2020 Pedro Luz