
1.编写玩家受击逻辑BeHit(atk,dir) (1.受击时得知受到的攻击力和受击方向 (2.受击时向受击方向被击飞一小段 (3.减去相应的生命值 2.编写基本小怪逻辑 (1.wander状态,在两点间巡逻 (2.当触发OnTouchThePlayer,通知玩家BeHit 3.编写了更多摘要和参数解释 4.更新的Dotween插件的版本
117 lines
3.3 KiB
C#
117 lines
3.3 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using Sirenix.OdinInspector;
|
||
|
||
|
||
/// <summary>
|
||
/// 敌人的基类,一般怪物都继承其而来
|
||
/// </summary>
|
||
public class Enemy : MonoBehaviour
|
||
{
|
||
// _____ _ _ _
|
||
// | __ \ | | | (_)
|
||
// | |__) | _| |__ | |_ ___
|
||
// | ___/ | | | '_ \| | |/ __|
|
||
// | | | |_| | |_) | | | (__
|
||
// |_| \__,_|_.__/|_|_|\___|
|
||
|
||
/// <summary>
|
||
/// 生命值上限
|
||
/// </summary>
|
||
[BoxGroup("属性")][Header("生命值上限")]
|
||
public float HP;
|
||
|
||
/// <summary>
|
||
/// 攻击力
|
||
/// </summary>
|
||
[BoxGroup("属性")][Header("攻击力")]
|
||
public float ATK;
|
||
|
||
/// <summary>
|
||
/// 速度
|
||
/// </summary>
|
||
[BoxGroup("属性")]
|
||
public float speed{get{return speed;} set{speed = value;}}
|
||
|
||
/// <summary>
|
||
/// 打死后掉多少金币
|
||
/// </summary>
|
||
[BoxGroup("属性")][Header("掉落金币数")]
|
||
public int coin;
|
||
|
||
/// <summary>
|
||
/// 怪物拥有的几种状态
|
||
/// </summary>
|
||
public enum State{wander,seek,atk,dead};
|
||
|
||
// _____ _ _
|
||
// | __ \ (_) | |
|
||
// | |__) | __ ___ ____ _| |_ ___
|
||
// | ___/ '__| \ \ / / _` | __/ _ \
|
||
// | | | | | |\ V / (_| | || __/
|
||
// |_| |_| |_| \_/ \__,_|\__\___|
|
||
|
||
/// <summary>
|
||
/// 当前生命值
|
||
/// </summary>
|
||
[ReadOnly][SerializeField][ProgressBar(0,10,0.15f,0.47f,0.74f)][BoxGroup("状态")]
|
||
protected float HPLeft;
|
||
|
||
/// <summary>
|
||
/// 当前状态
|
||
/// </summary>
|
||
[EnumPaging][SerializeField][ReadOnly][Header("当前状态")][BoxGroup("状态")]
|
||
protected State state;
|
||
|
||
// ______ _
|
||
// | ____| | |
|
||
// | |____ _____ _ __ | |_
|
||
// | __\ \ / / _ \ '_ \| __|
|
||
// | |___\ V / __/ | | | |_
|
||
// |______\_/ \___|_| |_|\__|
|
||
|
||
/// <summary>
|
||
/// 当怪物死的时候Call这个函数
|
||
/// </summary>
|
||
protected void OnDead(){}
|
||
|
||
/// <summary>
|
||
/// 当怪物触碰到玩家的时候Call这个
|
||
/// </summary>
|
||
protected virtual void OnTouchThePlayer(MyPlayer player){}
|
||
|
||
/// <summary>
|
||
/// 当怪物被打的时候触发
|
||
/// </summary>
|
||
/// <param name="hitMethod">攻击方式,枚举类型,具体看MyPlayer</param>
|
||
/// <param name="hitDir">受击方向,-1左,1右</param>
|
||
protected void OnBeHit(MyPlayer.AtkMethod hitMethod,int hitDir){}
|
||
|
||
/// <summary>
|
||
/// 当怪物发现玩家的时候Call这个
|
||
/// </summary>
|
||
protected void OnFindThePlayer(){}
|
||
|
||
|
||
// _____ _ _ _ _
|
||
// / ____| | | (_) (_)
|
||
// | | ___ | | |_ ___ _ ___ _ __
|
||
// | | / _ \| | | / __| |/ _ \| '_ \
|
||
// | |___| (_) | | | \__ \ | (_) | | | |
|
||
// \_____\___/|_|_|_|___/_|\___/|_| |_|
|
||
protected void OnCollisionEnter2D(Collision2D other)//当有物体碰上
|
||
{
|
||
if(other.gameObject.TryGetComponent<MyPlayer>(out MyPlayer player))
|
||
{OnTouchThePlayer(player);}//如果创到的是玩家,则Call事件
|
||
}
|
||
protected void OnTriggerEnter2D(Collider2D other)
|
||
{
|
||
if(other.gameObject.TryGetComponent<MyPlayer>(out MyPlayer player))
|
||
{OnFindThePlayer();}//如果监视范围出现玩家,则Call事件
|
||
}
|
||
|
||
|
||
|
||
}
|