Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity key detection

if (Input.GetKeyDown(KeyCode.Space))
        {
            print("space key was pressed");
        }
Comment

unity detect number key

// Replace the 1 with your number
if (Input.GetKeyDown(KeyCode.Alpha1)) {
  //Code here
}
Comment

unity key detection

    void Update()
    {
        if (Input.GetKeyDown("space"))
        {
            print("space key was pressed");
        }
    }
Comment

unity key detection


public static bool GetAlphaKeyValue(out int alphaKey)
{
    alphaKey = -1;

    if (Input.GetKeyDown(KeyCode.Alpha0) alphaKey = 0;
    else if (Input.GetKeyDown(KeyCode.Alpha1) alphaKey = 1;
    else if (Input.GetKeyDown(KeyCode.Alpha2) alphaKey = 2;
    else if (Input.GetKeyDown(KeyCode.Alpha3) alphaKey = 3;
    else if (Input.GetKeyDown(KeyCode.Alpha4) alphaKey = 4;
    else if (Input.GetKeyDown(KeyCode.Alpha5) alphaKey = 5;
    else if (Input.GetKeyDown(KeyCode.Alpha6) alphaKey = 6;
    else if (Input.GetKeyDown(KeyCode.Alpha7) alphaKey = 7;
    else if (Input.GetKeyDown(KeyCode.Alpha8) alphaKey = 8;
    else if (Input.GetKeyDown(KeyCode.Alpha9) alphaKey = 9;

    return alphaKey >= 0;
}

Comment

unity detect any key

if (Input.anyKey) {
  // Code here
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: prettier isnt working c# 
Csharp :: c# read file from path 
Csharp :: loop through all enum values in C# 
Csharp :: get time part from datetime as timestamp in c# 
Csharp :: take screenshot in c# 
Csharp :: ef core detach entity 
Csharp :: difference between executescalar and executenonquery and executereader 
Csharp :: C# HttpClient POST request 
Csharp :: C# Console multi language 
Csharp :: c# winforms textbox to int 
Csharp :: start command line from c# 
Csharp :: c# stop loop 
Csharp :: void update 
Csharp :: c# append multiline textbox 
Csharp :: new color unity 
Csharp :: datagridview column color c# 
Csharp :: WebClient c# with custom user agent 
Csharp :: how to get the current time in milliseconds .net 
Csharp :: how to find a gameobject in unity 
Csharp :: how to copy last element in list c# 
Csharp :: if unity 
Csharp :: how to move a gameobject to another object 
Csharp :: mvc 5 dropdownlist 
Csharp :: c# append text to file 
Csharp :: c# file directory selection 
Csharp :: list removeall unity 
Csharp :: scaffold single table to model ef core 
Csharp :: c# entity framework group by 
Csharp :: get last element of array c# 
Csharp :: move files from one folder to another using c# 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =