Long notes in a guitar hero like game

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

Could you be a little more specific? What's going on in your scene? What objects in the scene are relevant to the problem, and what components are attached to those objects? What do you expect to happen that isn't? Is the collision event missing? Is the logic failing?

I have a very long object that moves from right to left and another static object in the center of the screen who is the trigger,i need a way to check if the player is holding a key when it enters the trigger,if he dont stopeds pressing the key while inside trigger,and is still holding the button when my object leaves the trigger.

2 Answers

2

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;	
    }

Thanks,it worked.