Files
BABA_YAGA/Assets/Scripts/VFX/SukunaSlashEffect.cs
2026-03-26 20:27:19 +07:00

54 lines
1.5 KiB
C#

using UnityEngine;
public class SukunaSlashEffect : MonoBehaviour
{
[Header("Settings")]
public float duration = 0.2f;
public float maxScale = 5f;
public AnimationCurve scaleCurve = AnimationCurve.EaseInOut(0, 0, 1, 1);
[Header("Visuals")]
private MeshRenderer meshRenderer;
private MaterialPropertyBlock propBlock;
private float timer = 0f;
private static readonly int DissolveId = Shader.PropertyToID("_Dissolve");
void Awake()
{
meshRenderer = GetComponent<MeshRenderer>();
propBlock = new MaterialPropertyBlock();
}
void Start()
{
// Reset scale ban đầu
transform.localScale = new Vector3(maxScale, 0.1f, 0.1f);
}
void Update()
{
timer += Time.deltaTime;
float normalizedTime = timer / duration;
if (normalizedTime <= 1.0f)
{
// Mở rộng vệt chém theo chiều ngang (Y hoặc Z tùy mesh)
float currentScaleY = scaleCurve.Evaluate(normalizedTime) * maxScale;
transform.localScale = new Vector3(maxScale, currentScaleY, 1f);
// Điều khiển Shader bằng MaterialPropertyBlock
if (meshRenderer != null)
{
meshRenderer.GetPropertyBlock(propBlock);
propBlock.SetFloat(DissolveId, normalizedTime);
meshRenderer.SetPropertyBlock(propBlock);
}
}
else
{
// Tự hủy sau khi xong
Destroy(gameObject);
}
}
}