Files

70 lines
1.5 KiB
C#
Raw Permalink Normal View History

2025-05-13 05:19:58 +03:00
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<GameAction> actions = new List<GameAction>();
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<AudioSource>();
}
void OnGUI(){
}
// Update is called once per frame
void Update () {
if(actions != null && actions.Count > 0){
hud.SetAction(string.Format("Press <color=#00ff00ff>{0}</color> to <color=#ffff00ff>{1}</color>", actionKey.ToString(), actions[0].text));
if(Input.GetKeyDown(actionKey)){
actions[0].Execute(player);
}
}else{
hud.SetAction("");
}
}
}