Cute_demon_attacks/meng_yao/Assets/script/A_Fight/Bing.cs
2024-12-23 16:58:00 +08:00

56 lines
1.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bing : MonoBehaviour
{
public enemy Crole; // 角色对象,用来扣血
public Bullet bullet; // 子弹脚本
private float lastDamageTime = 0; // 上一次扣血的时间
private float lastDamageAllTime = 0; // 上一次灼烧效果的总时间
[Header("灼烧扣血间隔")]
public float attackTime; // 扣血的间隔时间
[Header("冰总时间")]
public float attackAllTime = 3; // 扣血的持续时间
[Header("冰消失时间")]
public float lifeTime = 3f; // 火焰的持续时间,默认 5 秒
private float spawnTime; // 记录火焰生成的时间
void Start()
{
Debug.Log("-------------------------");
spawnTime = Time.time; // 记录火焰对象的生成时间
Crole = transform.parent.GetComponent<enemy>();
}
void Update()
{
// 判断是否超过火焰存在的最大时间
if (Time.time - spawnTime > lifeTime)
{
Destroy(gameObject); // 超过时间后销毁物体
return; // 直接返回,不再执行后面的灼烧逻辑
}
// 这里可以加上灼烧的具体逻辑,比如伤害的扣除等
if (Crole != null && bullet != null)
{
// 进行灼烧扣血操作
if (Time.time - lastDamageAllTime > attackAllTime || lastDamageAllTime == 0)
{
if (Time.time - lastDamageTime > attackTime || attackTime == 0)
{
// 执行伤害逻辑
//Crole.bloodLoss(new object[] { Crole, bullet.role.Attack + bullet.bulletData.attack, bullet.attackObj.damageTyp, bullet.role });
//Debug.Log("灼烧扣血");
lastDamageTime = Time.time;
}
lastDamageAllTime = Time.time;
}
}
}
}