using UnityEngine; using System.Collections; using System.Collections.Generic; public class GameAction{ public GameAction(){ } public GameAction(GameObject obj, string description){ target = obj; text = description; } public GameObject target; public string text; public void Execute(GameObject caller){ Debug.Log("Action on target: " + target.name); target.SendMessage("OnAction", new ActionArgs(this, caller), SendMessageOptions.DontRequireReceiver); } } public class ActionArgs{ public GameAction Action; public GameObject Caller; public ActionArgs(GameAction action, GameObject caller){ Action = action; Caller = caller; } } public class ActionController : MonoBehaviour { public KeyCode actionKey = KeyCode.F; private static List actions = new List(); public HudController hud; public GameObject player; public static AudioSource audio; public static void AddAction(GameAction act){ actions.Add(act); } public static void RemoveAction(GameAction act){ actions.Remove(act); } void Start () { audio = GetComponent(); } void OnGUI(){ } // Update is called once per frame void Update () { if(actions != null && actions.Count > 0){ hud.SetAction(string.Format("Press {0} to {1}", actionKey.ToString(), actions[0].text)); if(Input.GetKeyDown(actionKey)){ actions[0].Execute(player); } }else{ hud.SetAction(""); } } }