RandomRotate.js 484 B

12345678910111213141516171819202122
  1. #pragma strict
  2. private var rotTarget:Quaternion;
  3. var rotateEverySecond:float = 1;
  4. private var lerpCounter:float;
  5. private var rotCache:Quaternion;
  6. function Start () {
  7. randomRot ();
  8. InvokeRepeating("randomRot", 0,rotateEverySecond);
  9. }
  10. function Update(){
  11. transform.rotation = Quaternion.Lerp(transform.rotation, rotTarget, lerpCounter*Time.deltaTime);
  12. lerpCounter++;
  13. }
  14. function randomRot () {
  15. rotTarget = Random.rotation;
  16. rotCache = transform.rotation;
  17. lerpCounter = 0;
  18. }