Search Unity

Is there a way to use GetKeyUp as a trigger using 2 input keys?

Discussion in 'Scripting' started by matthew77, Sep 24, 2017.

  1. matthew77

    matthew77

    Joined:
    Dec 17, 2016
    Posts:
    29
    Hi. Like the title says is there a way to use say shift+s or shift+b or whatever for key input?

    I'm currently using a C# script :

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class animation : MonoBehaviour {
    7.  
    8.  
    9.  
    10.     public Animator anim;
    11.  
    12.     // Use this for initialization
    13.     void Start () {
    14.         anim = GetComponent<Animator>();
    15.     }
    16.  
    17.     // Update is called once per frame
    18.     void Update () {
    19.         if (Input.GetKeyDown("d"))
    20.         {
    21.             anim.Play("drunk");
    22.         }
    23.  
    24.         if (Input.GetKeyDown("a"))
    25.         {
    26.             anim.Play("anim_runa_run_left");
    27.         }
    28.  
    29.     }
    30.  
    31.  
    32.     private void FixedUpdate()
    33.     {
    34.         if (Input.GetKeyUp("7"))
    35.         {
    36.             anim.Play("easy_FuncyBasic");
    37.         }
    38.         if (Input.GetKeyUp("2"))
    39.         {
    40.             anim.Play("breakdance");
    41.         }
    42.         if (Input.GetKeyUp("3"))
    43.         {
    44.             anim.Play("hard_BounceStep");
    45.         }
    46.         if (Input.GetKeyUp("4"))
    47.         {
    48.             anim.Play("normal_HipCircle");
    49.         }
    50.         if (Input.GetKeyUp("w"))
    51.         {
    52.             anim.Play("Grounded");
    53.         }
    54.         if (Input.GetKeyUp("u"))
    55.         {
    56.             anim.Play("upset");
    57.         }
    58.         if (Input.GetKeyUp("5"))
    59.         {
    60.             anim.Play("hard_BasicTurn");
    61.         }
    62.         if (Input.GetKeyUp("6"))
    63.         {
    64.             anim.Play("dance new");
    65.         }
    66.  
    67.         if (Input.GetKeyUp("s"))
    68.         {
    69.             anim.Play("75_19");
    70.         }
    71.         if (Input.GetKeyUp("e"))
    72.         {
    73.             anim.Play("eat2");
    74.         }
    75.         if (Input.GetKeyUp("l"))
    76.         {
    77.             anim.Play("laugh");
    78.         }
    79.         if (Input.GetKeyUp("KeyCode.LeftShift+b") )
    80.         {
    81.             anim.Play("backflip");
    82.         }
    83.  
    84.         if (Input.GetKeyUp("g"))
    85.         {
    86.             anim.Play("sitting");
    87.         }
    88.         if (Input.GetKeyUp("1"))
    89.         {
    90.             anim.Play("bench sit new");
    91.         }
    92.         if (Input.GetKeyUp("9"))
    93.         {
    94.             anim.Play("lay down");
    95.         }
    96.         if (Input.GetKeyUp("d"))
    97.         {
    98.             anim.Play("drinking");
    99.         }
    100.         if (Input.GetKeyUp("8"))
    101.         {
    102.             anim.Play("waterslide");
    103.         }
    104.         if (Input.GetKeyDown("KeyCode.UpArrow"))
    105.         {
    106.             anim.Play("grounded");
    107.         }
    108.         if (Input.GetKeyUp("s"))
    109.         {
    110.             anim.Play("swim");
    111.         }
    112.         if (Input.GetKeyUp("a"))
    113.         {
    114.             anim.Play("anim_runa_idle_left");
    115.         }
    116.     }
    117. }
    118.  
    Thanks in advance for any help you can give.
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,619
    One of these might be what you're looking for...

    Code (CSharp):
    1. if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.S))
    2.   Debug.Log("Shift+S down");
    3.  
    4. if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.S))
    5.   Debug.Log("Shift+S held");
    6.  
    7. if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyUp(KeyCode.S))
    8.   Debug.Log("Shift+S up");
    https://docs.unity3d.com/ScriptReference/Input.html