Files
Zheyuan Wu a23db068a3 RECOVER
2025-09-12 00:18:27 -05:00

47 lines
898 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NoteKey : MonoBehaviour
{
// Start is called before the first frame update
public GameObject defaultState;
public GameObject activeState;
public AudioSource sound;
public int state;
public int timer;
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
if (timer <= 0)
{
activeState.SetActive(false);
sound.Pause();
}
else {
timer--;
}
}
public void Play(int duration) {
timer = duration;
sound.Play(0);
activeState.SetActive(true);
}
private void OnCollisionEnter(Collision collision)
{
state = 1;
}
private void OnCollisionExit(Collision collision)
{
state = 0;
}
}