
1.编写塞钱箱逻辑 (1.初始为有钱 (2.创建事件,当被塞钱,修改塞钱箱状态 (3.创建事件,当被拿钱,修改塞钱箱状态 (*:修改塞钱箱继承自普通可交互物体 2.编写玩家塞钱逻辑 (1.创建交互按键,当检测到交互执行,执行所catch物体的OnCall,根据所catch物体不同触发不同的动作。当catch到的是塞钱箱,执行塞钱功能 (2.创建塞钱功能,持有特殊金币-1 3.修改爱欲品掉钱逻辑 (1.修改死亡事件,当检测到主人为地藏并且玩家身上已经没钱了的时候,生成一个特殊硬币 4.编写特殊硬币逻辑 (1.继承于可交互物体(×) (2.OnCall的时候触发玩家加钱功能 (3.物理层上不与除地面以外的其他东西碰撞 (4.捡拾上,给硬币添加一个子物体,通过子物体上的触发器和攻击类来判断捡拾与否 5.编写地藏拿钱攻击逻辑 (*.参照钟的逻辑 (1.新建地藏手 (2.新建组件:地藏手 (3.收到攻击信号后,从外部从上至下伸入一只手,伴随抖动,到一定位置后停止 (4.手有碰撞体,触碰到玩家时,对玩家造成伤害 (5.抄一段普通怪物的受击逻辑,当手被攻击了,触发动画,稍微抬起一小段,并且剧烈震动,同时通知主人被打 6.整理脚本 至此,关卡已经能按照正常的逻辑跑起来了
141 lines
4.5 KiB
C#
141 lines
4.5 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("状态")]
|
||
public 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>
|
||
public 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事件
|
||
}
|
||
}
|