Roman 6253bd856c 任务:搭建基本的系统
1.实装一些美术素材

2.完成木马召唤小怪攻击逻辑
(1.修复伊斯兰小怪的炸飞方向丢失Bug
(2.给伊斯兰小怪两种被击飞模式,当被普通武器攻击,轻度正常击飞,当被炸弹炸飞,剧烈飞出

3.完成木马喷射炸弹攻击逻辑
(1.与召唤小怪逻辑类似
(2.创建炸弹类
(3.3次喷射,仅确定首次力度和方向,后两次依靠倍率改变力度

4.完成炸弹逻辑,用于召唤炸弹和喷射炸弹两种攻击方式
(1.碰到东西即爆炸
(2.有一个触发器表示爆炸范围,当有东西进入
,尝试获取被炸对象接口,如果有,则将其加入攻击列表,爆炸时对列表中的每一个对象造成伤害,攻击力来自于owner
(3.当有物体离开触发器,康康它是否在列表中,若在,将其移除

5.整理脚本

下班
2021-12-12 23:40:14 +08:00

141 lines
4.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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事件
}
}