Answers for "unity get key from string"

C
0

unity get key from string

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using System.Linq;

public class Lifes : MonoBehaviour
{
    public string CustomKey;

    // Start is called before the first frame update
    void Start()
    {
        // Check if the key is uppercase - if so then "CustomKey" will be changed to lowercase.
        // Check https://docs.unity3d.com/Manual/class-InputManager.html for the key families.
        if(CustomKey.Any(char.IsUpper))
        {
            CustomKey = CustomKey.ToLower();
        }
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyDown(CustomKey))
        {
            Debug.Log(CustomKey + " got pressed.");
        }
    }
}
Posted by: Guest on August-06-2021

Code answers related to "C"

Browse Popular Code Answers by Language