169 lines
5.0 KiB
C#
Raw Normal View History

任务:搭建基本的系统 1.编写以撒逻辑 (1.继承于Enemy (2.编写OnSave(男童)事件,当有男童被解救,会触发以撒的这个事件,后续逻辑等待讨论 (3.具有冲撞和闪电两种攻击方式,通过类似地藏的方式轮回随机决定攻击方式 (4.编写冲撞攻击逻辑 ((*.创建鬼魂脚本 ((*.创建鬼魂预制体,需要内含触发器 ((1.当执行,以玩家为中心向周围一圈固定距离随机方向的某处召唤鬼魂,并记录下此时自身到玩家的方向 ((2.等待一小段时间,令鬼魂以记录方向冲撞出去,利用Tweener动画营造一种先抖一下然后猛地创过来的感觉 ((3.动画结束后,鬼魂逐渐消隐 ((4.消隐结束后,删除游戏物体 ((5.冲撞过程中具有攻击判定,若创到玩家,触发玩家的受击事件,同时获取主人的攻击力传给玩家 (3.编写闪电攻击逻辑 ((1.当执行,在玩家头顶一定距离处生成鬼魂 ((2.淡入显示鬼魂,一小段时间后,命令鬼魂发动落雷攻击 ((3.发动时,激活场景内的巨型落雷,同时更改落雷的x位置到鬼魂的x,子物体具有触发器,(每帧)检测到玩家在内则对玩家造成伤害 ((4.在极短的时间后关闭落雷同时开始淡出鬼魂 ((5.淡出结束后删除游戏物体 2.编写男童逻辑 (1.继承于Interactive (2.编写解救男童逻辑 ((*.修改Interactive基类,新增OnCallCancel事件,当交互键抬起时触发一次 ((*.新增男童状态的枚举类型,包含:wait、saving、OK三个状态 ((*:新增一个变量记录男童状态 ((1.重写OnCall事件,当OnCall,修改状态至saving ((2.Update回调中,若处于saving状态,则开始减少CDLeft,同时判断CDLeft是否耗尽,若耗尽,触发OnSave ((3.编写OnSave函数,修改状态至OK,通知owner自己已经OnSave ((4.重写OnCallCancel事件,当触发,判定状态,若处于saving状态,则修改状态至wait,恢复CDLeft ((*.使得玩家救人的时候无法移动,而当交互键抬起,重新获得移动能力 ((*.修改可交互基类,当玩家交互过程中丢失catching,触发可交互物体的中断,同时告知玩家交互中断,触发中断事件 ((5.解救结束后,通知玩家解救结束 至此,以撒的Boss逻辑还差首尾部分 加速吧
2021-12-17 01:27:10 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using Sirenix.OdinInspector;
/// <summary>
/// 以撒类,控制以撒Boss
/// </summary>
public class YiSa : Enemy
{
// _____ _ _ _
// | __ \ | | | (_)
// | |__) | _| |__ | |_ ___
// | ___/ | | | '_ \| | |/ __|
// | | | |_| | |_) | | | (__
// |_| \__,_|_.__/|_|_|\___|
/// <summary>
/// 攻击之间的间隔时间
/// </summary>
[Header("攻击之间的间隔时间")][FoldoutGroup("以撒")]
public float timeBetweenAttacks;
/// <summary>
/// 攻击用鬼魂的预制体
/// </summary>
[Header("攻击用鬼魂的预制体")][FoldoutGroup("预制体")]
public GameObject goust;
/// <summary>
/// 鬼魂攻击玩家时,生成位置离玩家的距离
/// </summary>
[Header("鬼魂攻击玩家时,生成位置离玩家的距离")][FoldoutGroup("以撒")]
public float atkOffsetDistance;
// _____ _ _
// | __ \ (_) | |
// | |__) | __ ___ ____ _| |_ ___
// | ___/ '__| \ \ / / _` | __/ _ \
// | | | | | |\ V / (_| | || __/
// |_| |_| |_| \_/ \__,_|\__\___|
/// <summary>
/// 返回类型为协程、参数为空的委托类型
/// </summary>
private delegate IEnumerator Action();
private MyPlayer player;
// _____ _ _ ____ _
// / ____| | | | _ \ | |
// | | __ _| | | |_) | __ _ ___| | __
// | | / _` | | | _ < / _` |/ __| |/ /
// | |___| (_| | | | |_) | (_| | (__| <
// \_____\__,_|_|_|____/ \__,_|\___|_|\_\
void Start(){
Init();
//测试用开启
StartCoroutine(StartAATK());
}
// _ _ _
// | \ | | | |
// | \| | ___ _ __ _ __ ___ __ _| |
// | . ` |/ _ \| '__| '_ ` _ \ / _` | |
// | |\ | (_) | | | | | | | | (_| | |
// |_| \_|\___/|_| |_| |_| |_|\__,_|_|
private void Init(){
//找到必要的物体和组件
player = FindObjectOfType<MyPlayer>();
}
/// <summary>
/// 执行一次攻击
/// </summary>
private IEnumerator StartAATK(){
//等待攻击间隔
yield return new WaitForSeconds(timeBetweenAttacks);
//决定行动
Action action = DecideAAction();
//开始行动
StartCoroutine(action());
}
/// <summary>
/// 决定行动的函数
/// </summary>
private Action DecideAAction(){
Action action;
///从0、1中随机生成一种
int r = Random.Range(0,2);
if(r == 0)
action = Rush;
else
action = Lighting;
return action;
}
private IEnumerator Rush(){
yield return new WaitForEndOfFrame();
Debug.Log("以撒使用了冲撞");
//当以撒使用冲撞时
//首先构建一个生成位置,以玩家为中心,向随机位置偏移固定距离便是
Vector3 appearPos = (
//玩家位置
player.transform.position +
//加上定长随机方向偏移量
new Vector3(
Random.Range(-1f,1f),Random.Range(-1f,1f),0
).normalized *
atkOffsetDistance
);
//在该位置生成一个鬼魂
YiSaGoust t = Instantiate(
goust,
appearPos,
Quaternion.identity
).GetComponent<YiSaGoust>();
//让鬼魂淡出
Tweener tweener = t.GetComponent<SpriteRenderer>().DOFade(1,0.5f);
//记录一下本次攻击的冲撞方向
Vector2 rushDir = player.transform.position - t.transform.position;
//告知该鬼魂执行冲撞攻击
yield return new WaitForSeconds(1f);
t.RushATK(rushDir);
//ATKEnd();
}
private IEnumerator Lighting(){
yield return new WaitForEndOfFrame();
Debug.Log("以撒使用了落雷");
//在玩家头顶某位置召唤鬼魂
YiSaGoust t = Instantiate(
goust,player.transform.position +
new Vector3(0,2f,0),Quaternion.identity
).GetComponent<YiSaGoust>();
//0.5秒淡入显示鬼魂
Tweener tweener = t.GetComponent<SpriteRenderer>().DOFade(1,0.5f);
//给玩家一秒的反应时间
yield return new WaitForSeconds(1f);
t.LightningATK();
//ATKEnd();
}
/// <summary>
/// 攻击结束的时候触发,重新开始新一轮攻击
/// </summary>
public void ATKEnd(){StartCoroutine(StartAATK());}
// ______ _
// | ____| | |
// | |____ _____ _ __ | |_
// | __\ \ / / _ \ '_ \| __|
// | |___\ V / __/ | | | |_
// |______\_/ \___|_| |_|\__|
/// <summary>
/// 当有男童被救的时候从男童触发
/// </summary>
public void OnSave(Boy boy){
}
}