gameDevTeacher

Random Start Rotation

Jul 9th, 2022 (edited)
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CoinController : MonoBehaviour
  6. {
  7.  
  8. // Fix entire system to Set y Rotation to a random degree between 0 and 359
  9.     [SerializeField] private float _rotationSpeed = 0.01f;
  10.     private bool _canRotate = false;
  11.  
  12.     private float timer;
  13.     // Start is called before the first frame update
  14.     void Start()
  15.     {
  16.         timer = Random.Range(0f,2f);
  17.     }
  18.  
  19.     // Update is called once per frame
  20.     void Update()
  21.     {
  22.          if (timer > 0) { timer -= 1 * Time.deltaTime; } else { _canRotate = true; }
  23.  
  24.         // Rotation
  25.         if (_canRotate)
  26.         {
  27.             transform.eulerAngles = new Vector3(0f,transform.eulerAngles.y + _rotationSpeed, 0f);
  28.         }
  29.        
  30.  
  31.         // Float
  32.  
  33.     }
  34. }
Add Comment
Please, Sign In to add comment