Roman 5bff5da713 任务:搭建基本的系统
1.修改爱欲品类,解决多个附身的问题
(1.已有变量标记玩家是否正被抓着
(*.当玩家被爱欲品抓住,让玩家记住这个爱欲品,用来后面被多个缠上时清空它的挣脱次数
(2.当爱欲品创到玩家,检查目前是否已经被附身,若是,使用父类的touched函数,也就是普通小怪的,用来创飞玩家,同时,清空当前附身着的爱欲品的挣脱次数
(3.修改爱欲品附身时的跟踪方式,原先为一次定位后不再更改,但如果遇到多只爱欲品的情况,则可能被击飞,此时附身中的爱欲品不会跟踪。修改至攻击中每帧重新定位。

2.编写地藏的敲钟攻击逻辑
(1.钟上浮Tween动画
(2.Tween动画结束事件,开启开关,同时StartContinue,等待一定时间后关闭开关,用来触发攻击结束事件
(3.开关打开时,每帧向玩家发射射线,若能击中玩家,受伤方式等待讨论确认。若不能,则无事可做。

3.整理脚本结构,编写注释、摘要和分层

至此,地藏的敲钟攻击逻辑基本完成
2021-12-10 00:23:50 +08:00

170 lines
5.1 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 DG.Tweening;
using Sirenix.OdinInspector;
/// <summary>
/// 撞钟类,控制地藏头上的钟
/// </summary>
public class Bell : MonoBehaviour
{
// _____ _ _ _
// | __ \ | | | (_)
// | |__) | _| |__ | |_ ___
// | ___/ | | | '_ \| | |/ __|
// | | | |_| | |_) | | | (__
// |_| \__,_|_.__/|_|_|\___|
/// <summary>
/// 攻击前置动作钟上浮多少距离
/// </summary>
[Header("攻击前置动作钟上浮多少距离")]
public float upDistance;
/// <summary>
/// 攻击将会持续多长时间
/// </summary>
[Header("攻击将会持续多长时间")]
public float atkTime;
/// <summary>
/// 主人也就是地藏Boss
/// </summary>
[HideInInspector]
public DiZang owner;
/// <summary>
/// 钟飞上去将要花费多少时间(降下来也是这个值)
/// </summary>
[Header("钟飞上去将要花费多少时间(降下来也是这个值)")]
public float upTime;
// _____ _ _
// | __ \ (_) | |
// | |__) | __ ___ ____ _| |_ ___
// | ___/ '__| \ \ / / _` | __/ _ \
// | | | | | |\ V / (_| | || __/
// |_| |_| |_| \_/ \__,_|\__\___|
/// <summary>
/// 当前正在攻击吗
/// </summary>
[SerializeField][Button][ReadOnly][Header("当前正在攻击吗(不包括钟上下过程))")]
private bool isAtking = false;
private MyPlayer player;
/// <summary>
/// 浮动动画,用来重启浮动动画解决Tween的一些局限性问题
/// </summary>
private Tweener floatTweener;
// _____ _ _ ____ _
// / ____| | | | _ \ | |
// | | __ _| | | |_) | __ _ ___| | __
// | | / _` | | | _ < / _` |/ __| |/ /
// | |___| (_| | | | |_) | (_| | (__| <
// \_____\__,_|_|_|____/ \__,_|\___|_|\_\
void Start(){
//启动浮动动画
RestartFloat();
}
void Update(){
//如果钟正在攻击
if(isAtking){
//创建一条从钟射向玩家的射线
Ray2D ray = new Ray2D(
(Vector2)transform.position,
(Vector2)( player.transform.position - transform.position)
);
Debug.DrawRay(ray.origin,ray.direction * 1500,Color.red);
//获取射线的碰撞结果
RaycastHit2D hit2D;
hit2D = Physics2D.Raycast(ray.origin,ray.direction);
if(hit2D){
Debug.Log(hit2D.collider.name);
}
}
}
// _ _ _
// | \ | | | |
// | \| | ___ _ __ _ __ ___ __ _| |
// | . ` |/ _ \| '__| '_ ` _ \ / _` | |
// | |\ | (_) | | | | | | | | (_| | |
// |_| \_|\___/|_| |_| |_| |_|\__,_|_|
/// <summary>
/// 介于Tweener的特性经常需要重新创建钟浮动的动画
/// </summary>
private void RestartFloat(){
if(floatTweener != null){
floatTweener.Kill();
}
Tweener tweener = transform.DOShakePosition(5f,0.3f,1,150,false,false);
tweener.SetLoops(-1);
tweener.SetEase(Ease.InQuad);
floatTweener = tweener;
}
// ______ _
// | ____| | |
// | |____ _____ _ __ | |_
// | __\ \ / / _ \ '_ \| __|
// | |___\ V / __/ | | | |_
// |______\_/ \___|_| |_|\__|
/// <summary>
/// 从主人那里得到攻击指令后触发
/// </summary>
public void ATK(MyPlayer player){
//指定一下攻击目标
this.player = player;
//创建和执行上浮动画
Tweener tweener = transform.DOLocalMoveY(
transform.position.y + upDistance,
upTime
);
//创建并加入上浮动画结束事件
TweenCallback action = () => {
//标记自己开始攻击
isAtking = true;
//重启浮动动画
RestartFloat();
//等待攻击结束
StartCoroutine(WaitAndTurnDownThebutton());
};
tweener.OnComplete(action);
}
/// <summary>
/// 上浮动画结束的时候触发
/// </summary>
/// <returns></returns>
private IEnumerator WaitAndTurnDownThebutton(){
//等待攻击时长结束
yield return new WaitForSeconds(atkTime);
//标记攻击结束
isAtking = false;
//触发自身攻击结束功能
ATKEnd();
}
/// <summary>
/// 攻击结束的时候触发
/// </summary>
private void ATKEnd(){
//创建动画让钟回去
Tweener tweener =
transform.DOMoveY(transform.position.y - upDistance,upTime);
//创建和添加结束事件
TweenCallback action = () => {
//重启浮动动画
RestartFloat();
//告诉主人,攻击结束,开始下一个轮回
owner.ATKEnd();
};
tweener.OnComplete(action);
}
}