Cute_demon_attacks/meng_yao/Assets/Prefabs/charatar/enemy/SnowHpControl.cs

64 lines
2.3 KiB
C#
Raw Normal View History

2024-12-14 21:15:57 +08:00
using UnityEngine;
using DG.Tweening;
public class SnowHpControl : MonoBehaviour
{
public Vector3 minScale = new Vector3(0f, 0.1f, 1f); // <20><>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
public Vector3 maxScale = new Vector3(1f, 0.1f, 1f); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public float duration = 1f; // <20><>min<69><6E>max<61><78>ʱ<EFBFBD><CAB1>
public float moveSpeed = 0.005f; // <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
public float fadeDuration = 0f; // <20><>ʧʱ<CAA7><EFBFBD><E4A3A8><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ʵ<EFBFBD>ּ<EFBFBD>ʱ<EFBFBD><CAB1>ʧ<EFBFBD><CAA7>
public float moveDistance = 2f; // <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public Canvas targetCanvas; // Ŀ<><EFBFBD><EABBAD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7>UIԪ<49><D4AA><EFBFBD>ڸû<DAB8><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>
private Renderer rend; // <20><><EFBFBD>ڻ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Renderer<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͸<EFBFBD><CDB8><EFBFBD><EFBFBD>
private Vector3 initialPosition;
void Start()
{
targetCanvas = transform.parent.GetComponent<Canvas>();
// <20><>ȡRenderer
rend = GetComponent<Renderer>();
// ȷ<><C8B7>Ѫ<EFBFBD><D1AA><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EABBAD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷλ<C8B7><CEBB><EFBFBD><EFBFBD>
if (targetCanvas.renderMode == RenderMode.WorldSpace)
{
// <20><><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EABBAD><EFBFBD><EFBFBD>WorldSpaceģʽ<C4A3><CABD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
initialPosition = transform.position;
}
else
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ScreenSpaceģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫת<D2AA><D7AA><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EAB5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
initialPosition = targetCanvas.worldCamera.ScreenToWorldPoint(transform.position);
}
// <20><>ʼ<EFBFBD><CABC>Ѫ<EFBFBD><D1AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
transform.localScale = minScale;
// ʹ<><CAB9>DOTween<65><6E><EFBFBD><EFBFBD><EFBFBD>Ŷ<EFBFBD><C5B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
transform.DOScale(maxScale, duration).SetEase(Ease.InOutQuad).OnComplete(StartFading);
// <20><><EFBFBD><EFBFBD>Ѫ<EFBFBD><D1AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>ʼλ<CABC><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD> `moveDistance` <20><>λ<EFBFBD><CEBB>
transform.DOMoveY(initialPosition.y + moveDistance, duration).SetEase(Ease.InOutQuad);
}
private void StartFading()
{
// <20><><EFBFBD><EFBFBD>fadeDurationΪ<6E>㣬ֱ<E3A3AC><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (fadeDuration == 0f)
{
Destroy(gameObject);
}
else
{
// <20><><EFBFBD><EFBFBD>fadeDuration<6F><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3A3AC>ʹ<EFBFBD><CAB9>DOTween
// ͨ<><CDA8>DOTween<65><6E><EFBFBD><EFBFBD>͸<EFBFBD><CDB8><EFBFBD>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD>
DOTween.ToAlpha(() => rend.material.color, x => rend.material.color = x, 0f, fadeDuration).OnComplete(() =>
{
Destroy(gameObject); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD>
});
}
}
}