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!
supreme outlet
golden goose mid star
supreme clothing
yeezy 700
curry shoes
yeezy outlet
paul george shoes
supreme shirt
moncler
goyard
Unity Debug Class: Unity provides the Debug class which includes methods like Log, LogWarning, and LogError for basic logging. While this is essential, a more structured approach involves custom debugging tools.
IEEE projects for cse
Custom Debugging Scripts: Create custom scripts in your Unity project to handle debugging functionalities.
python projects for final year students
Post a Comment