using System.Collections; using System.Collections.Generic; using UnityEngine; using Sirenix.OdinInspector; /// /// 敌人的基类,一般怪物都继承其而来 /// public class Enemy : MonoBehaviour { // _____ _ _ _ // | __ \ | | | (_) // | |__) | _| |__ | |_ ___ // | ___/ | | | '_ \| | |/ __| // | | | |_| | |_) | | | (__ // |_| \__,_|_.__/|_|_|\___| /// /// 生命值上限 /// [BoxGroup("属性")][Header("生命值上限")] public float HP; /// /// 攻击力 /// [BoxGroup("属性")][Header("攻击力")] public float ATK; /// /// 速度 /// [BoxGroup("属性")][Header("速度")] public float speed; /// /// 打死后掉多少金币 /// [BoxGroup("属性")][Header("掉落金币数")] public int coin; /// /// 怪物拥有的几种状态 /// public enum State{wander,seek,atk,dead}; // _____ _ _ // | __ \ (_) | | // | |__) | __ ___ ____ _| |_ ___ // | ___/ '__| \ \ / / _` | __/ _ \ // | | | | | |\ V / (_| | || __/ // |_| |_| |_| \_/ \__,_|\__\___| /// /// 当前生命值 /// [ReadOnly][SerializeField][ProgressBar(0,10,0.15f,0.47f,0.74f)] protected float HPLeft; /// /// 当前状态 /// [EnumPaging][SerializeField][ReadOnly][Header("当前状态")] protected State state; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } // ______ _ // | ____| | | // | |____ _____ _ __ | |_ // | __\ \ / / _ \ '_ \| __| // | |___\ V / __/ | | | |_ // |______\_/ \___|_| |_|\__| /// /// 当怪物死的时候Call这个函数 /// protected void OnDead(){} /// /// 当怪物触碰到玩家的时候Call这个 /// protected void OnTouchThePlayer(){} /// /// 当怪物被打的时候触发 /// /// 攻击方式,枚举类型,具体看MyPlayer /// 受击方向,-1左,1右 protected void OnBeHit(MyPlayer.AtkMethod hitMethod,int hitDir){} /// /// 当怪物发现玩家的时候Call这个 /// protected void OnFindThePlayer(){} // _____ _ _ _ _ // / ____| | | (_) (_) // | | ___ | | |_ ___ _ ___ _ __ // | | / _ \| | | / __| |/ _ \| '_ \ // | |___| (_) | | | \__ \ | (_) | | | | // \_____\___/|_|_|_|___/_|\___/|_| |_| protected void OnCollisionEnter2D(Collision2D other)//当有物体碰上 { if(other.gameObject.TryGetComponent(out MyPlayer player)) {OnTouchThePlayer();}//如果创到的是玩家,则Call事件 } protected void OnTriggerEnter2D(Collider2D other) { if(other.gameObject.TryGetComponent(out MyPlayer player)) {OnFindThePlayer();}//如果监视范围出现玩家,则Call事件 } }