dronkowitz

RingRotation.cs

Jul 13th, 2021 (edited)
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using TMPro;
  5.  
  6.  
  7. public class RingRotation : MonoBehaviour
  8. {
  9.     public float startSpeed = 40;
  10.     public float endSpeed = 10;
  11.     public int degrees = 0;
  12.     public int rotationdegrees = 0;
  13.     public bool justadded;
  14.     public Rigidbody RB;
  15.     public TMP_Text LevelAdd;
  16.     // Start is called before the first frame update
  17.     void Start()
  18.     {
  19.         StartCoroutine(Spin());
  20.     }
  21.  
  22.     // Update is called once per frame
  23.     void Update()
  24.     {
  25.        
  26.     }
  27.     IEnumerator Spin()
  28.     {
  29.         LevelAdd.text = GameInstance.goalring.ToString();
  30.         RB.angularVelocity = new Vector3(0, startSpeed, 0);
  31.         while (rotationdegrees < 10)
  32.         {
  33.  
  34.             if (Mathf.Abs(transform.rotation.y) > 0.9f && justadded == false)
  35.             {
  36.                 rotationdegrees += 1;
  37.                 justadded = true;
  38.                 RB.angularVelocity = new Vector3(0, RB.angularVelocity.y - 1, 0);
  39.  
  40.             }
  41.  
  42.             if (Mathf.Abs(transform.rotation.y) < 0.9f)
  43.             {
  44.                 justadded = false;
  45.             }
  46.  
  47.             yield return new WaitForSeconds(Time.deltaTime);
  48.  
  49.  
  50.  
  51.         }
  52.         RB.angularVelocity = Vector3.zero;
  53.         transform.rotation = Quaternion.Euler(0, 180, 0);
  54.         GameInstance.goalring += 1;
  55.         LevelAdd.text = GameInstance.goalring.ToString();
  56.        
  57.  
  58.     }
  59.  
  60.     }
  61.  
Add Comment
Please, Sign In to add comment