Files
MRCS/Assets/_MrCs/Scripts/Item/StartGameItem.cs
2025-11-27 17:18:09 +08:00

85 lines
2.0 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using DamageNumbersPro;
using DG.Tweening;
using DragonLi.Core;
using DragonLi.Frame;
using Mirror;
using UnityEngine;
public class StartGameItem : NetworkBehaviour,IDamagable
{
public Collider box;
public GameObject model;
[NonSerialized]
public int HpIndex;
public void ApplyDamage(float value, int info, Transform _sender,int score)
{
if (!isServer)
{
return;
}
HpIndex--;
RpcShowDamageNumber(_sender.position,value,false);
if (HpIndex <= 0)
{
Over();
return;
}
Shake();
}
public float Health { get; set; }
private void Start()
{
HpIndex = 3;
originalPos=transform.position;
}
// 飘字由客户端显示
private void RpcShowDamageNumber(Vector3 pos, float dmg, bool crit)
{
GameManager.Ins.RpcShowDamageNumber(dmg, pos, crit);
}
public void Over()
{
// if(GameManager.Ins.gameState== GameState.Playing)
// return;
// Debug.Log("开始游戏");
// GameManager.Ins.GameStart();
// NetworkServer.Destroy(gameObject);
// CoroutineTaskManager.Instance.WaitSecondTodo(() =>
// {
//
// }, 2f);
// box.enabled = false;
// model.SetActive(false);
}
private Tween shakeTween;
[Header("Shake Settings")]
public float duration = 0.3f; // 抖动持续时间
public float strength = 0.2f; // 抖动强度
public int vibrato = 20; // 抖动的振动次数
private bool isShaking = false;
private Vector3 originalPos;
public void Shake()
{
if (isShaking) return;
isShaking = true;
shakeTween = transform.DOShakePosition(duration, strength, vibrato)
.OnComplete(() =>
{
transform.localPosition = originalPos;
isShaking = false;
});
}
}