religion/Assets/Scripts/DiZang.cs
Roman b1063a379f 任务:搭建基本的系统
1.搭建地藏测试场景
(1.放置单向平台
(2.限制摄像机范围
(3.设置相机跟踪
(4.放置图片素材

2.编写地藏boss逻辑
(1.继承自Enemy(内含基本的变量和事件)
(2.当玩家进入戒备范围,startContinue攻击功能

3.创建塞钱箱脚本,目前为空,仅调试用

4.编写召唤攻击逻辑
(1.编写工具类,投掷点,记录投掷力度、方向。
(2.在地藏中保存两套投掷点
(3.攻击时判定玩家位置,进而决定要使用哪一套投掷点
(4.从投掷点获取信息,然后初始化生成的爱欲品
(5.等待召唤攻击的后摇时间,然后发信号表示攻击结束,进入下一个循环

至此,佛教Boss的召唤攻击方式基本开发完毕
2021-12-08 23:52:17 +08:00

157 lines
5.2 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>
/// 地藏Boss类继承于Enemy
/// </summary>
public class DiZang : Enemy
{
// _____ _ _ _
// | __ \ | | | (_)
// | |__) | _| |__ | |_ ___
// | ___/ | | | '_ \| | |/ __|
// | | | |_| | |_) | | | (__
// |_| \__,_|_.__/|_|_|\___|
/// <summary>
/// 攻击之间的间隔时间
/// </summary>
[Header("攻击之间的间隔时间")][FoldoutGroup("地藏")]
public float timeBetweenAttacks;
/// <summary>
/// 塞钱箱
/// </summary>
private MoneyBox moneyBox;
private delegate IEnumerator Action();
private enum PlayerState{,};
private MyPlayer player;
/// <summary>
/// 到底在上面还是下面生成爱欲品的玩家位置Y轴的界限
/// </summary>
[Header("到底在上面还是下面生成爱欲品的玩家位置Y轴的界限")]
public float aiYuPinBuildLimit;
/// <summary>
/// 爱欲品小怪的预制体,召唤功能会用到
/// </summary>
[Header("爱欲品怪物预制体")][FoldoutGroup("地藏")]
public GameObject aiYuPin;
/// <summary>
/// 场景上方的落怪点,用来召唤爱欲品
/// </summary>
[Header("场景上方的落怪点组")][ListDrawerSettings][FoldoutGroup("地藏")]
public List<ThrowingPoint> throwingPointGroupUp;
/// <summary>
/// 场景下方的落怪点,用来召唤爱欲品
/// </summary>
[Header("场景下方的落怪点组")][ListDrawerSettings][FoldoutGroup("地藏")]
public List<ThrowingPoint> throwingPointGroupDown;
/// <summary>
/// 本次使用的落怪点位置组
/// </summary>
private List<ThrowingPoint> throwingPointGroupUse;
/// <summary>
/// 使用召唤爱欲品后有多少时间的后摇
/// </summary>
public float CallAiYuPinEndTime;
private delegate void NullAction();
private void Init(){
moneyBox = FindObjectOfType<MoneyBox>();
player = FindObjectOfType<MyPlayer>();
}
protected override void OnFindThePlayer(Transform target){
if(state == State.wander){
state = State.atk;
StartCoroutine("ATK");
}
}
void Start(){
Init();
}
private new IEnumerator ATK(){
//等待攻击间隔
yield return new WaitForSeconds(timeBetweenAttacks);
//决定行动
//如果有钱,则执行拿钱
if(moneyBox.hasMoney)StartCoroutine(TakeTheMoney());
else{
//否则,随机执行召唤或者敲钟
Action action =
((Random.Range(-1f,0f) > 0) ? (Action)RingTheBell : (Action)CallAiYuPin);
StartCoroutine(action());
}
}
/// <summary>
/// 召唤爱欲品的时候Call这个
/// </summary>
private IEnumerator CallAiYuPin(){
yield return new WaitForEndOfFrame();
//确定玩家在上半边还是下半边
PlayerState playerState =
((player.transform.position.y > aiYuPinBuildLimit) ? PlayerState.: PlayerState.);
//根据玩家位置状态确定所用落怪位置组
throwingPointGroupUse =
((playerState == PlayerState.) ?
throwingPointGroupUp : throwingPointGroupDown);
//创建一个储存生成的爱欲品的列表用于使他们在一段时间后开始Seek
List<AiYuPin> aiYuPins = new List<AiYuPin>();
//遍历位置组
foreach(ThrowingPoint t in throwingPointGroupUse){
//生成一个爱欲品
AiYuPin temp =Instantiate(
aiYuPin,
t.transform.position,//在位置组中元素的位置
Quaternion.identity
).GetComponent<AiYuPin>();
//初始化爱欲品
//该状态为wander使其先保持不动
temp.state = State.wander;
//修改爱欲品面部朝向
if(t.dir.x == -1) temp.transform.rotation = Quaternion.Euler(
temp.transform.rotation.x,
-180f,
temp.transform.localScale.z
);
//根据投掷点内信息给予爱欲品投掷速度
temp.GetComponent<Rigidbody2D>().velocity = t.dir * t.strength;
//把这个爱欲品加入列表
aiYuPins.Add(temp);
}
//一段时间后使他们开始Seek
yield return new WaitForSeconds(0.8f);
foreach(AiYuPin a in aiYuPins){
a.state = State.seek;
}
//等待攻击后摇结束
yield return new WaitForSeconds(CallAiYuPinEndTime);
//发送信号,本次攻击宣告结束
ATKEnd();
}
/// <summary>
/// 敲钟的时候Call这个
/// </summary>
private IEnumerator RingTheBell(){
yield return new WaitForEndOfFrame();
Debug.Log("地藏正在敲钟");
}
/// <summary>
/// 拿钱的时候Call这个
/// </summary>
private IEnumerator TakeTheMoney(){
yield return new WaitForEndOfFrame();
Debug.Log("地藏正在拿钱");
}
private void ATKEnd(){StartCoroutine(ATK());}
}