
1.搭建地藏测试场景 (1.放置单向平台 (2.限制摄像机范围 (3.设置相机跟踪 (4.放置图片素材 2.编写地藏boss逻辑 (1.继承自Enemy(内含基本的变量和事件) (2.当玩家进入戒备范围,startContinue攻击功能 3.创建塞钱箱脚本,目前为空,仅调试用 4.编写召唤攻击逻辑 (1.编写工具类,投掷点,记录投掷力度、方向。 (2.在地藏中保存两套投掷点 (3.攻击时判定玩家位置,进而决定要使用哪一套投掷点 (4.从投掷点获取信息,然后初始化生成的爱欲品 (5.等待召唤攻击的后摇时间,然后发信号表示攻击结束,进入下一个循环 至此,佛教Boss的召唤攻击方式基本开发完毕
141 lines
4.6 KiB
C#
141 lines
4.6 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using Sirenix.OdinInspector;
|
||
|
||
|
||
/// <summary>
|
||
/// 敌人的基类,包含一些基本的功能和事件的虚函数
|
||
/// </summary>
|
||
public class Enemy : MonoBehaviour
|
||
{
|
||
// _____ _ _ _
|
||
// | __ \ | | | (_)
|
||
// | |__) | _| |__ | |_ ___
|
||
// | ___/ | | | '_ \| | |/ __|
|
||
// | | | |_| | |_) | | | (__
|
||
// |_| \__,_|_.__/|_|_|\___|
|
||
|
||
/// <summary>
|
||
/// 生命值上限
|
||
/// </summary>
|
||
[FoldoutGroup("属性")][Header("生命值上限")]
|
||
public float HP;
|
||
|
||
/// <summary>
|
||
/// 攻击力
|
||
/// </summary>
|
||
[FoldoutGroup("属性")][Header("攻击力")]
|
||
public float ATK;
|
||
|
||
/// <summary>
|
||
/// 速度
|
||
/// </summary>
|
||
[FoldoutGroup("属性")][Header("移动速度")]
|
||
public float speed;
|
||
/// <summary>
|
||
/// 打死后掉多少金币
|
||
/// </summary>
|
||
[FoldoutGroup("属性")][Header("掉落金币数")]
|
||
public int coin;
|
||
/// <summary>
|
||
/// 怪物拥有的几种状态
|
||
/// </summary>
|
||
public enum State{wander,seek,atk,dead};
|
||
/// <summary>
|
||
/// 此时怪物能否被攻击
|
||
/// </summary>
|
||
[FoldoutGroup("状态")][Header("当前是否能被攻击")][ReadOnly]
|
||
public bool canBeHit = true;
|
||
/// <summary>
|
||
/// 当前状态
|
||
/// </summary>
|
||
[EnumPaging][SerializeField][ReadOnly][Header("当前状态")][FoldoutGroup("状态")]
|
||
public State state;
|
||
|
||
// _____ _ _
|
||
// | __ \ (_) | |
|
||
// | |__) | __ ___ ____ _| |_ ___
|
||
// | ___/ '__| \ \ / / _` | __/ _ \
|
||
// | | | | | |\ V / (_| | || __/
|
||
// |_| |_| |_| \_/ \__,_|\__\___|
|
||
|
||
/// <summary>
|
||
/// 当前生命值
|
||
/// </summary>
|
||
[ReadOnly][SerializeField][ProgressBar(0,10,0.15f,0.47f,0.74f)][FoldoutGroup("状态")]
|
||
protected float HPLeft;
|
||
|
||
|
||
// ______ _
|
||
// | ____| | |
|
||
// | |____ _____ _ __ | |_
|
||
// | __\ \ / / _ \ '_ \| __|
|
||
// | |___\ V / __/ | | | |_
|
||
// |______\_/ \___|_| |_|\__|
|
||
|
||
/// <summary>
|
||
/// 当怪物死的时候Call这个函数
|
||
/// </summary>
|
||
protected virtual void OnDead(){}
|
||
|
||
/// <summary>
|
||
/// 当怪物触碰到玩家的时候Call这个
|
||
/// </summary>
|
||
protected virtual void OnTouchThePlayer(MyPlayer player){}
|
||
|
||
/// <summary>
|
||
/// 当怪物被打的时候触发
|
||
/// </summary>
|
||
/// <param name="hitMethod">攻击方式,枚举类型,具体看MyPlayer</param>
|
||
/// <param name="hitDir">受击方向,-1左,1右</param>
|
||
public virtual void OnBeHit(MyPlayer.AtkMethod hitMethod,int hitDir){}
|
||
|
||
/// <summary>
|
||
/// 当怪物发现玩家的时候Call这个
|
||
/// </summary>
|
||
protected virtual void OnFindThePlayer(Transform target){}
|
||
/// <summary>
|
||
/// 当怪物着地的时候触发一次
|
||
/// </summary>
|
||
public virtual void OnRetouchedTheGround(){}
|
||
|
||
// _ _ _
|
||
// | \ | | | |
|
||
// | \| | ___ _ __ _ __ ___ __ _| |
|
||
// | . ` |/ _ \| '__| '_ ` _ \ / _` | |
|
||
// | |\ | (_) | | | | | | | | (_| | |
|
||
// |_| \_|\___/|_| |_| |_| |_|\__,_|_|
|
||
|
||
/// <summary>
|
||
/// 看看死了没
|
||
/// </summary>
|
||
protected bool CheckDead(){return !(HPLeft > 0);}
|
||
|
||
|
||
// _____ _ _ _ _
|
||
// / ____| | | (_) (_)
|
||
// | | ___ | | |_ ___ _ ___ _ __
|
||
// | | / _ \| | | / __| |/ _ \| '_ \
|
||
// | |___| (_) | | | \__ \ | (_) | | | |
|
||
// \_____\___/|_|_|_|___/_|\___/|_| |_|
|
||
protected void OnCollisionEnter2D(Collision2D other)//当有物体碰上
|
||
{
|
||
if(other.collider.gameObject.TryGetComponent<MyPlayer>(out MyPlayer player))
|
||
{OnTouchThePlayer(player);}//如果创到的是玩家,则Call事件
|
||
//如果被镰刀创到,Call一下OnBeHit事件,传入攻击方式和攻击来袭方向
|
||
else if(other.collider.gameObject.TryGetComponent<Sickle>(out Sickle sickle))
|
||
{OnBeHit(MyPlayer.AtkMethod.镰刀,
|
||
(transform.position.x -
|
||
sickle.transform.position.x > 0) ? -1 : 1);
|
||
Destroy(sickle.gameObject);}
|
||
else if(other.gameObject.tag == "地面")
|
||
{OnRetouchedTheGround();}
|
||
}
|
||
protected virtual void OnTriggerEnter2D(Collider2D other)
|
||
{
|
||
if(other.gameObject.TryGetComponent<MyPlayer>(out MyPlayer player))
|
||
{OnFindThePlayer(other.transform);}//如果监视范围出现玩家,则Call事件
|
||
}
|
||
}
|