I'd like to get in the habit of posting more code. I tend to avoid it as anything interesting to me is usually overly complex or client specific. That said, if you found this snippet helpful I'd love to hear from you and I'll keep posting bite sized components that I find useful.
Example of the component:
Code:
public class KeyboardCommandManager : MonoBehaviour { [System.Serializable] public struct KeyAndResponse { public KeyCode Key; public UnityEvent Response; public bool EditorOnly; } public KeyAndResponse[] KeysAndResponses; private List<KeyAndResponse> ActiveKeys; private void Awake() { ActiveKeys = new List<KeyAndResponse>(); if(KeysAndResponses!=null) { for (int i = 0; i < KeysAndResponses.Length; i++) { var keyAndResponse = KeysAndResponses[i]; if(!keyAndResponse.EditorOnly || Application.isEditor) { ActiveKeys.Add(keyAndResponse); } } } } void Update() { if (Input.anyKeyDown) { for (int i = 0; i < ActiveKeys.Count; i++) { var keyAndResponse = ActiveKeys[i]; if(Input.GetKeyDown(keyAndResponse.Key)) keyAndResponse.Response.Invoke(); } } } }
3 comments:
Uff saved me a bunch of minutes, thanks man!
fila shoes
adidas superstar shoes
golden goose
supreme clothing
kevin durant shoes
nike cortez women
yeezy boost 350
adidas yeezy boost
curry 5 shoes
ferragamo belt
supreme outlet
golden goose mid star
supreme clothing
yeezy 700
curry shoes
yeezy outlet
paul george shoes
supreme shirt
moncler
goyard
Post a Comment