Commit 1
This commit is contained in:
53
Assets/Scripts/VFX/SukunaSlashEffect.cs
Normal file
53
Assets/Scripts/VFX/SukunaSlashEffect.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user