2024-12-14 21:15:57 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using DG.Tweening;
|
2024-12-18 16:55:26 +08:00
|
|
|
|
using UnityEngine.UI;
|
2024-12-14 21:15:57 +08:00
|
|
|
|
|
|
|
|
|
public class SnowHpControl : MonoBehaviour
|
|
|
|
|
{
|
2024-12-18 14:17:24 +08:00
|
|
|
|
public Vector3 minScale = new Vector3(0.5f, 0.5f, 1f); // <20><>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
|
|
|
|
|
public Vector3 maxScale = new Vector3(1.5f, 1.5f, 1f); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
public float duration = 1f; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD>ʱ<EFBFBD><CAB1>
|
|
|
|
|
public float moveDistance = 5f; // <20><>Ծ<EFBFBD><D4BE>ˮƽ<CBAE><C6BD><EFBFBD><EFBFBD>
|
2024-12-18 16:55:26 +08:00
|
|
|
|
public float fadeDuration = 0.5f; // <20><>ʧʱ<CAA7><CAB1>
|
2024-12-14 21:15:57 +08:00
|
|
|
|
public Canvas targetCanvas; // Ŀ<>껭<EFBFBD><EABBAD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7>UIԪ<49><D4AA><EFBFBD>ڸû<DAB8><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>
|
2024-12-18 20:44:20 +08:00
|
|
|
|
public int direction;//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
2024-12-14 21:15:57 +08:00
|
|
|
|
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()
|
2024-12-18 20:44:20 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-29 17:30:00 +08:00
|
|
|
|
public void CreateText(bool isGoodDamege=false)
|
2024-12-14 21:15:57 +08:00
|
|
|
|
{
|
|
|
|
|
targetCanvas = transform.parent.GetComponent<Canvas>();
|
|
|
|
|
|
|
|
|
|
// <20><>ȡRenderer
|
|
|
|
|
rend = GetComponent<Renderer>();
|
|
|
|
|
|
2024-12-18 14:17:24 +08:00
|
|
|
|
// ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD>ʼλ<CABC><CEBB><EFBFBD><EFBFBD>Ŀ<EFBFBD>껭<EFBFBD><EABBAD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷλ<C8B7><CEBB><EFBFBD><EFBFBD>
|
2024-12-14 21:15:57 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-18 14:17:24 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>λ<EFBFBD>ã<EFBFBD><C3A3>ڳ<EFBFBD>ʼλ<CABC>ø<EFBFBD><C3B8><EFBFBD><EFBFBD><EFBFBD>
|
2024-12-18 20:44:20 +08:00
|
|
|
|
float randomX;
|
2024-12-18 21:08:22 +08:00
|
|
|
|
if (direction == 0)
|
2024-12-18 20:44:20 +08:00
|
|
|
|
{
|
|
|
|
|
randomX = Random.Range(moveDistance / 4f, moveDistance)+moveDistance/2;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
randomX = Random.Range(-moveDistance, -moveDistance / 4f)-moveDistance/2;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-18 14:17:24 +08:00
|
|
|
|
float randomY = Random.Range(-moveDistance / 4f, 0); // <20><>Y<EFBFBD><59><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
transform.position = initialPosition;
|
2024-12-14 21:15:57 +08:00
|
|
|
|
|
2024-12-18 14:17:24 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>minScale<6C><65>maxScale֮<65>䣩
|
|
|
|
|
float randomScaleX = Random.Range(minScale.x, maxScale.x);
|
|
|
|
|
float randomScaleY = Random.Range(minScale.y, maxScale.y);
|
|
|
|
|
transform.localScale = new Vector3(randomScaleX, randomScaleY, 1f);
|
2024-12-14 21:15:57 +08:00
|
|
|
|
|
2024-12-29 17:30:00 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC>С
|
|
|
|
|
Vector3 finalScale = isGoodDamege ? maxScale * 2f : maxScale; // <20><><EFBFBD><EFBFBD><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŵ<EFBFBD>1.5<EFBFBD><EFBFBD>
|
|
|
|
|
|
2024-12-18 14:17:24 +08:00
|
|
|
|
// ʹ<><CAB9>DOTween<65><6E><EFBFBD><EFBFBD>Ծ<EFBFBD><D4BE><EFBFBD><EFBFBD>
|
|
|
|
|
Sequence sequence = DOTween.Sequence();
|
2024-12-16 17:46:38 +08:00
|
|
|
|
|
2024-12-18 14:17:24 +08:00
|
|
|
|
// 1. <20><>Ծ<EFBFBD><D4BE><EFBFBD><EFBFBD><F0BDA5B1><EFBFBD>
|
2024-12-18 20:44:20 +08:00
|
|
|
|
sequence.Append(transform.DOJump(new Vector3(initialPosition.x + randomX, initialPosition.y + randomY), 0.3f, 1, 0.5f)
|
2024-12-18 14:17:24 +08:00
|
|
|
|
.SetEase(Ease.OutQuad) // <20><>ԾЧ<D4BE><D0A7><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>OutQuad<61><64><EFBFBD><EFBFBD>Ծ<EFBFBD><D4BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD><F0BDA5B1><EFBFBD>
|
2024-12-16 17:46:38 +08:00
|
|
|
|
);
|
2024-12-18 14:17:24 +08:00
|
|
|
|
//sequence.Join(transform.DOMoveY(initialPosition.y -( randomY + moveDistance) / 2f, 0.6f)
|
|
|
|
|
// .SetEase(Ease.OutQuad) // <20><>Ծ<EFBFBD>ĸ߶ȣ<DFB6><C8A3><EFBFBD>X<EFBFBD><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ծ<EFBFBD><D4BE><EFBFBD><EFBFBD>
|
2024-12-16 17:46:38 +08:00
|
|
|
|
//);
|
2024-12-29 17:30:00 +08:00
|
|
|
|
|
|
|
|
|
sequence.Join(transform.DOScale(finalScale, 0.5f) // ͬʱ<CDAC><CAB1><EFBFBD>ƴ<EFBFBD>С<EFBFBD><D0A1><EFBFBD>ӳ<EFBFBD>ʼֵ<CABC><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
2024-12-18 14:17:24 +08:00
|
|
|
|
.SetEase(Ease.OutBack) // ʹ<><CAB9>OutBack<63><6B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>
|
|
|
|
|
);
|
2024-12-16 17:46:38 +08:00
|
|
|
|
|
2024-12-18 14:17:24 +08:00
|
|
|
|
// 2. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD>䵭<F0BDA5B1><E4B5AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-12-18 16:55:26 +08:00
|
|
|
|
sequence.Append(transform.DOScale(Vector3.zero, 0.5f).SetEase(Ease.Linear)); // <20><>СЧ<D0A1><D0A7><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>ʧ<EFBFBD>ĸо<C4B8>
|
|
|
|
|
sequence.Append(transform.GetComponent<Text>().DOFade(0f, fadeDuration).OnComplete(() =>
|
2024-12-14 21:15:57 +08:00
|
|
|
|
{
|
2024-12-18 20:44:20 +08:00
|
|
|
|
|
2024-12-18 14:17:24 +08:00
|
|
|
|
Destroy(gameObject); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD>
|
|
|
|
|
}));
|
2024-12-14 21:15:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|