Unity 3D Command Solution

Asked

Viewed 68 times

0

I need a C# script that makes 2 commands by pressing a single EX key: (I want to make my character crouch by pressing "c" and when to press the character back up) could someone help me ?

1 answer

1


Basically you need a beacon to mark whether he’s crouching 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
    }
  • ok friend I use the Unity version 2017 so some commands are not recognized ex: the Keyeventargs

  • Sorry, since the tag is in C# I thought the answer might help, but the concept is the same, creates a flag to indicate how the character is in the moment, and when pressing the key, checks the flag and directs the behavior, to lower or raise, and remember to update the flag whenever the character changes, as well as in the example that is in the answer. I hope it helps, a little xD

Browser other questions tagged

You are not signed in. Login or sign up in order to post.