Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine.UI;
- using UnityEngine;
- public class KeyBinder : MonoBehaviour
- {
- [SerializeField] KeyManager.Binds bindTo;
- public string BindedAction { get => bindTo.ToString();}
- [SerializeField] Button bindingButton;
- [SerializeField] Text keyLabel;
- [Header("Auto Setup (Optional)")]
- [Tooltip("Rename this object to action it will be bind to")]
- [SerializeField] GameObject autoNaming;
- [Tooltip("Make this label text match the action it will bind to")]
- [SerializeField] Text actionLabel;
- KeyManager manager;
- void OnValidate()
- {
- if(autoNaming != null) gameObject.name = BindedAction;
- if(actionLabel != null) actionLabel.text = BindedAction;
- }
- void Start()
- {
- //Get the key manager
- manager = KeyManager.i;
- //Upon clicking bind button it will send this to be bind in manager
- bindingButton.onClick.AddListener(delegate {manager.BeginBind(this);});
- //Display the keycode of action binded to text label
- DisplayKeyLabel(manager.ReflectActionKeycode(BindedAction).GetValue(manager).ToString());
- }
- public void DisplayKeyLabel(string display)
- {
- //Display the given text to label
- keyLabel.text = display;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement