Skip to content

Instantly share code, notes, and snippets.

@Manamongods
Last active April 22, 2020 15:49
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 Manamongods/001f08fdef392885ac5d100d0cb6a4b8 to your computer and use it in GitHub Desktop.
Save Manamongods/001f08fdef392885ac5d100d0cb6a4b8 to your computer and use it in GitHub Desktop.
//Steffen Vetne made this
//Creative Commons 0
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class RandomSpinner : MonoBehaviour
{
//Fields
public float speedMultiplier = 100;
public Vector2 speedRange = new Vector2(1, 2);
private Vector3 axis;
private float speed;
//Lifecycle
private void OnEnable()
{
transform.localRotation = Random.rotationUniform;
axis = Random.onUnitSphere;
speed = Random.Range(speedRange.x, speedRange.y);
}
private void Update()
{
Quaternion rot = Quaternion.AngleAxis(speedMultiplier * speed * Time.deltaTime, axis);
transform.localRotation = rot * transform.localRotation;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment