using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using Sirenix.OdinInspector;
///
/// 以撒类,控制以撒Boss
///
public class YiSa : Enemy
{
// _____ _ _ _
// | __ \ | | | (_)
// | |__) | _| |__ | |_ ___
// | ___/ | | | '_ \| | |/ __|
// | | | |_| | |_) | | | (__
// |_| \__,_|_.__/|_|_|\___|
///
/// 攻击之间的间隔时间
///
[Header("攻击之间的间隔时间")][FoldoutGroup("以撒")]
public float timeBetweenAttacks;
///
/// 攻击用鬼魂的预制体
///
[Header("攻击用鬼魂的预制体")][FoldoutGroup("预制体")]
public GameObject goust;
///
/// 鬼魂攻击玩家时,生成位置离玩家的距离
///
[Header("鬼魂攻击玩家时,生成位置离玩家的距离")][FoldoutGroup("以撒")]
public float atkOffsetDistance;
// _____ _ _
// | __ \ (_) | |
// | |__) | __ ___ ____ _| |_ ___
// | ___/ '__| \ \ / / _` | __/ _ \
// | | | | | |\ V / (_| | || __/
// |_| |_| |_| \_/ \__,_|\__\___|
///
/// 返回类型为协程、参数为空的委托类型
///
private delegate IEnumerator Action();
private MyPlayer player;
// _____ _ _ ____ _
// / ____| | | | _ \ | |
// | | __ _| | | |_) | __ _ ___| | __
// | | / _` | | | _ < / _` |/ __| |/ /
// | |___| (_| | | | |_) | (_| | (__| <
// \_____\__,_|_|_|____/ \__,_|\___|_|\_\
void Start(){
Init();
//测试用开启
StartCoroutine(StartAATK());
}
// _ _ _
// | \ | | | |
// | \| | ___ _ __ _ __ ___ __ _| |
// | . ` |/ _ \| '__| '_ ` _ \ / _` | |
// | |\ | (_) | | | | | | | | (_| | |
// |_| \_|\___/|_| |_| |_| |_|\__,_|_|
private void Init(){
//找到必要的物体和组件
player = FindObjectOfType();
}
///
/// 执行一次攻击
///
private IEnumerator StartAATK(){
//等待攻击间隔
yield return new WaitForSeconds(timeBetweenAttacks);
//决定行动
Action action = DecideAAction();
//开始行动
StartCoroutine(action());
}
///
/// 决定行动的函数
///
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();
//让鬼魂淡出
Tweener tweener = t.GetComponent().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();
//0.5秒淡入显示鬼魂
Tweener tweener = t.GetComponent().DOFade(1,0.5f);
//给玩家一秒的反应时间
yield return new WaitForSeconds(1f);
t.LightningATK();
//ATKEnd();
}
///
/// 攻击结束的时候触发,重新开始新一轮攻击
///
public void ATKEnd(){StartCoroutine(StartAATK());}
// ______ _
// | ____| | |
// | |____ _____ _ __ | |_
// | __\ \ / / _ \ '_ \| __|
// | |___\ V / __/ | | | |_
// |______\_/ \___|_| |_|\__|
///
/// 当有男童被救的时候从男童触发
///
public void OnSave(Boy boy){
}
}