Solution for command in Unity 3D [closed]

0

I need a C # script that does 2 commands with a single EX key: (I want to make my character squat by pressing "c" and when I press again the character to rise again) could anyone help me?

    
asked by anonymous 09.02.2018 / 21:41

1 answer

1

Basically you need a flag to check whether it is crouched or not.

private boolean agachado = false;

    public void keyPressEvent(object sender, KeyEventArgs e){
       if(e.KeyCode == Keys.C){

          if(agachado){
            levantar();            
           }else{
             agachar();
           }
       }

    }


     public void agachar(){
       this.agachado = true;

     //resto do codigo pra agachar
     }

     public void levantar(){
       this.agachado = false;

       //codigo pra levantar
    }
    
09.02.2018 / 21:53