Horje
converting alpha1  into int unity Code Example
converting alpha1 into int unity
Dictionary<KeyCode, System.Action> keyCodeDic = new Dictionary<KeyCode, System.Action>();

void Start()
{
    //Register Keycodes to match each function to call
    const int alphaStart = 48;
    const int alphaEnd = 57;

    int paramValue = 0;
    for (int i = alphaStart; i <= alphaEnd; i++)
    {
        KeyCode tempKeyCode = (KeyCode)i;

        //Use temp variable to prevent it from being capture
        int temParam = paramValue;
        keyCodeDic.Add(tempKeyCode, () => MethodCall(temParam));
        paramValue++;
    }
}

void MethodCall(int keyNum)
{
    Debug.Log("Pressed: " + keyNum);
}


void Update()
{
    //Loop through the Dictionary and check if the Registered Keycode is pressed
    foreach (KeyValuePair<KeyCode, System.Action> entry in keyCodeDic)
    {
        //Check if the keycode is pressed
        if (Input.GetKeyDown(entry.Key))
        {
            //Check if the key pressed exist in the dictionary key
            if (keyCodeDic.ContainsKey(entry.Key))
            {
                //Debug.Log("Pressed " + entry.Key);

                //Call the function stored in the Dictionary's value
                keyCodeDic[entry.Key].Invoke();
            }
        }
    }
}




Csharp

Related
C# console out restore Code Example C# console out restore Code Example
C# program that print charater from A to Z and it's corresponding number Code Example C# program that print charater from A to Z and it's corresponding number Code Example
c# onmousedown. unity Code Example c# onmousedown. unity Code Example
Web forms switch page Code Example Web forms switch page Code Example
vb.net convert int32 into boolean array stack overflow Code Example vb.net convert int32 into boolean array stack overflow Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7