using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//View层 Button
public class BaseSkill : MonoBehaviour
{
public string mName;
public float mColdTime;
public System.Action<string> mReleaseSkill;
private bool mIsCold = false;
private float mCurrentTime = 0;
private void Start()
{
this.GetComponent<Button>().onClick.AddListener(
delegate
{
//释放技能
if (mReleaseSkill != null) { mReleaseSkill(this.name); }
//开始技能的冷却
});
}
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//Controller层 技能管理列表
public class SkillMgr : MonoBehaviour
{
private GameObject player;
private List<BaseSkill> skillList = new List<BaseSkill>();
private void Start()
{
player = GameObject.Find("Player");
//将当前节点下的技能按名字加入列表末尾
skillList.AddRange(this.gameObject.GetComponentsInChildren<BaseSkill>());
foreach (var item in skillList)
{
item.mReleaseSkill = mReleaseSkill;
}
}
private void mReleaseSkill(string nName)
{
Debug.Log("释放技能:" + nName);
player.GetComponent<Animator>().SetTrigger(nName);
}
}