I’m trying to make a musical game,and right now trying to implement long notes(the ones you have to hold a button from the entire note,but the script i created dont work,it doenst show any error,just dont work.
bool squee2 = false;
bool a = false;
void Update(){
if (Input.GetKey("up")&& a == true ){
squee2 = true;
}
if (Input.GetKeyUp("up")){
squee2 = false;;
sistema.score -= 1;
}
}
void OnTriggerEnter(Collider other) {
a = true;
}
void OnTriggerExit(Collider other) {
a = false;
if (squee2 == true) {
// do stuff
Based on your reply, I think this logic could do the job: the variable pressed is set to true if the key was already pressed when the entering the trigger; if the key is released, pressed returns to false; when exiting the trigger, pressed is assigned to squee2. This way, squee2 will only become true if the key has been pressed during the whole trigger:
bool pressed = false;
bool squee2 = false;
void OnTriggerEnter(Collider other) {
// pressed tells if key was pressed when entering the trigger:
pressed = Input.GetKey("up");
}
void Update(){
if (Input.GetKeyUp("up")){
pressed = false; // detects if key was released
}
}
void OnTriggerExit(Collider other) {
// copy variable pressed to squee2 upon trigger exit:
squee2 = pressed;
}