eastbayeff

Untitled

Nov 24th, 2021
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Note : MonoBehaviour
  6. {
  7.     public int Lane;
  8.     private Detector detector;
  9.     WaitForSeconds oneSecondWait;
  10.  
  11.     private bool earlyHit, perfectHit, lateHit = false;
  12.  
  13.     private void Awake()
  14.     {
  15.         detector = FindObjectOfType<Detector>();
  16.     }
  17.  
  18.     private void Start()
  19.     {
  20.         oneSecondWait = new WaitForSeconds(1);
  21.  
  22.         Debug.Log(detector);
  23.         detector.OnButtonPressed.AddListener(CheckHitOnLane);
  24.  
  25.         StartCoroutine(HitRanges());
  26.     }
  27.  
  28.     // note spawns
  29.     // note is given its lane data upon instantiation
  30.     // note knows when it is "hittable" during coroutine
  31.     // note needs to "get hit" when button pressed
  32.  
  33.     public void SetLane(int lane)
  34.     {
  35.         Lane = lane;
  36.         gameObject.name += lane.ToString();
  37.     }
  38.  
  39.     public void CheckHitOnLane(int lane)
  40.     {
  41.         if (lane != Lane)
  42.         {
  43.             Debug.Log($"miss {gameObject.name}");
  44.             return;
  45.         }
  46.  
  47.         if (earlyHit)
  48.             Debug.Log("early");
  49.  
  50.         if (perfectHit)
  51.             Debug.Log("perfect");
  52.  
  53.         if (lateHit)
  54.             Debug.Log("late");
  55.  
  56.         Destroy(gameObject);
  57.        
  58.     }
  59.  
  60.     IEnumerator HitRanges()
  61.     {
  62.         yield return oneSecondWait;
  63.  
  64.         earlyHit = true;
  65.  
  66.         yield return oneSecondWait;
  67.  
  68.         earlyHit = false;
  69.         perfectHit = true;
  70.  
  71.         yield return oneSecondWait;
  72.  
  73.         perfectHit = false;
  74.         lateHit = true;
  75.  
  76.         yield return oneSecondWait;
  77.  
  78.         lateHit = false;
  79.  
  80.     }
  81.  
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment