unity 中一个类 同时继承MonoBehaviour 和接口类,应该怎么做呢
----------------------------------------------------------------------------------------------------------------
TC_IWeapon 类如下所示
using System.Collections.Generic; using UnityEngine; //using System.Collections; public interface TC_IWeapon { List<TC_BaseStat> Stat { get; set; } void PerformAttack(); }
using System.Collections; using System.Collections.Generic; using UnityEngine; using System; public class TC_Sword : MonoBehaviour,TC_IWeapon { }
可以看到直接 把 接口 继承这样写是错误的
右键,选择“快速操作和重构”
选择“实现接口”
VS自动 实现接口
----------------------------------------------------------------------------------------------------------------
unity接口类继承以及继承MonoBehaviourunity 中一个类 同时继承MonoBehaviour 和接口类,应该怎么做呢
重复上面的步骤
TC_IWeapon不变
删除 注释内的内容(绿字/* */ 的内容),即可实现unity 中一个类 同时继承MonoBehaviour 和接口类
参考资料:
1.
2.Weapon Equipping | Making a Simple RPG - Unity 5 Tutorial (Part 5)
3.
4.