Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Note : MonoBehaviour
- {
- public int Lane;
- private Detector detector;
- WaitForSeconds oneSecondWait;
- private bool earlyHit, perfectHit, lateHit = false;
- private void Awake()
- {
- detector = FindObjectOfType<Detector>();
- }
- private void Start()
- {
- oneSecondWait = new WaitForSeconds(1);
- Debug.Log(detector);
- detector.OnButtonPressed.AddListener(CheckHitOnLane);
- StartCoroutine(HitRanges());
- }
- // note spawns
- // note is given its lane data upon instantiation
- // note knows when it is "hittable" during coroutine
- // note needs to "get hit" when button pressed
- public void SetLane(int lane)
- {
- Lane = lane;
- gameObject.name += lane.ToString();
- }
- public void CheckHitOnLane(int lane)
- {
- if (lane != Lane)
- {
- Debug.Log($"miss {gameObject.name}");
- return;
- }
- if (earlyHit)
- Debug.Log("early");
- if (perfectHit)
- Debug.Log("perfect");
- if (lateHit)
- Debug.Log("late");
- Destroy(gameObject);
- }
- IEnumerator HitRanges()
- {
- yield return oneSecondWait;
- earlyHit = true;
- yield return oneSecondWait;
- earlyHit = false;
- perfectHit = true;
- yield return oneSecondWait;
- perfectHit = false;
- lateHit = true;
- yield return oneSecondWait;
- lateHit = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment