Question by
skullygang · Aug 15, 2021 at 06:05 AM ·
unity 5
How to make long Notes for rhythm game in unity
The code I currently have for my long note game object is
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class LongNoteObject : MonoBehaviour { public bool canBePressed; public float startTime, endTime; public KeyCode keyToPress; public GameObject hitEffect, goodEffect, perfectEffect, missEffect;
// Start is called before the first frame update
void Start()
{
startTime = 0f;
endTime = 0f;
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown(keyToPress))
startTime = Time.time;
{
if(canBePressed)
{
gameObject.SetActive(false);
//GameManager.instance.NoteHit();
if(Mathf.Abs(transform.position.y) > 0.25){
Debug.Log("Hit");
GameManager.instance.NormalHit();
Instantiate(hitEffect, transform.position, hitEffect.transform.rotation);
}
else if (Mathf.Abs(transform.position.y) > 0.05f)
{
Debug.Log("Good");
GameManager.instance.GoodHit();
Instantiate(goodEffect, transform.position, goodEffect.transform.rotation);
}
else
{
Debug.Log("Perfect");
GameManager.instance.PerfectHit();
Instantiate(perfectEffect, transform.position, perfectEffect.transform.rotation);
}
}
}
}
private void OnTriggerEnter2D(Collider2D other)
{
if(other.tag == "Activator")
{
canBePressed = true;
}
}
private void OnTriggerExit2D(Collider2D other)
{
if(other.tag == "Activator" && gameObject.activeSelf)
{
canBePressed = false;
GameManager.instance.NoteMissed();
Instantiate(missEffect, transform.position, missEffect.transform.rotation);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
IOS平台下,Unity无法获取GPS,IOS平台下Unity无法获取GPS 0 Answers
UnityException: Failed to run serialization 0 Answers
Is it possible to hooking Unity engine? -1 Answers
top down 2d shooter direction of enemies 0 Answers