Last active
April 22, 2020 15:49
-
-
Save Manamongods/001f08fdef392885ac5d100d0cb6a4b8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//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