using System.Collections; using System.Collections.Generic; using UnityEngine; using Sirenix.OdinInspector; /// /// 基督小怪类,继承自爱欲品 /// public class JiDu : AiYuPin { // _____ _ _ _ // | __ \ | | | (_) // | |__) | _| |__ | |_ ___ // | ___/ | | | '_ \| | |/ __| // | | | |_| | |_) | | | (__ // |_| \__,_|_.__/|_|_|\___| /// /// 攻击相对于自身的位置偏移量 /// [FoldoutGroup("基督")][Header("攻击相对于自身的位置偏移量")] public float atkPositionOffset; /// /// 攻击范围 /// [FoldoutGroup("基督")][Header("攻击范围")] public float atkRange; /// /// 攻击时实例化的攻击器 /// [FoldoutGroup("基督")][Header("闪电攻击器")] public GameObject lightningAttack; // _____ _ _ // | __ \ (_) | | // | |__) | __ ___ ____ _| |_ ___ // | ___/ '__| \ \ / / _` | __/ _ \ // | | | | | |\ V / (_| | || __/ // |_| |_| |_| \_/ \__,_|\__\___| /// /// 自身到玩家的位置 /// [SerializeField][ReadOnly][FoldoutGroup("状态")][Header("自身到玩家的位置")] private float distanceToPlayer; // _____ _ _ ____ _ // / ____| | | | _ \ | | // | | __ _| | | |_) | __ _ ___| | __ // | | / _` | | | _ < / _` |/ __| |/ / // | |___| (_| | | | |_) | (_| | (__| < // \_____\__,_|_|_|____/ \__,_|\___|_|\_\ void Update(){ //如果处于追踪状态,则每帧执行Seek if(state == State.seek) Seek(target); } // _ _ _ // | \ | | | | // | \| | ___ _ __ _ __ ___ __ _| | // | . ` |/ _ \| '__| '_ ` _ \ / _` | | // | |\ | (_) | | | | | | | | (_| | | // |_| \_|\___/|_| |_| |_| |_|\__,_|_| /// /// 如果处于Seek状态,则每帧执行一次 /// /// 追踪目标 protected override void Seek(Transform target){ //计算自己与玩家的距离 distanceToPlayer = Mathf.Abs(target.position.x - transform.position.x); //如果距离小于攻击范围,则发动攻击 if(distanceToPlayer < atkRange)Atk(); //否则执行爱欲品的Seek,移动追向目标 else base.Seek(target); } /// /// 攻击的时候触发 /// private void Atk(){ //修改自身状态至攻击 state = State.atk; //判定一下自身和玩家的位置,确定攻击方向 int atkDir = ((target.position.x - transform.position.x > 0) ? 1:-1); //生成一个攻击器预制体,并根据攻击方向给予X轴偏移 LightningAttackAdministrator l = Instantiate( lightningAttack, new Vector3( transform.position.x + atkPositionOffset * atkDir, transform.position.y, transform.position.z ), Quaternion.identity ).GetComponent(); //初始化一下攻击器,给予攻击器主人和方向😍 l.owner = this; l.dir = atkDir; } // ______ _ // | ____| | | // | |____ _____ _ __ | |_ // | __\ \ / / _ \ '_ \| __| // | |___\ V / __/ | | | |_ // |______\_/ \___|_| |_|\__| /// /// 碰到玩家的时候触发。对于基督小怪来说,玩家碰到它会收到伤害,与继承到的爱欲品不同,但与爱欲品继承的相同,所以返回到父类的父类执行 /// 我超,不能,base.base,老老实实抄一遍代码吧 /// /// 玩家 protected override void OnTouchThePlayer(MyPlayer player){ //告诉玩家,你被攻击了 player.OnBeHit(ATK, ((transform.position.x - player.transform.position.x) > 0) ? 1 : -1);//通过自身位置和玩家位置的比较来返回玩家本次的受击方向 } /// /// 当攻击器攻击结束,Call这个,把状态恢复至Seek /// public void OnAtkEnd(){state = State.seek;} }