using UnityEngine;
///
/// 石头人砸地冲击波 · 触发脚本
/// 挂在平躺的 Quad 上,砸地命中帧调用 Play()
///
[RequireComponent(typeof(Renderer))]
public class ShockwaveRing : MonoBehaviour
{
[Header("扩散持续时间(秒)")]
public float duration = 0.6f;
[Header("起始缩放(可选,Play 时自动应用)")]
public Vector3 startScale = new Vector3(8f, 8f, 1f);
private Material mat;
private float timer = -1f;
private void Awake()
{
Initialize();
}
void Start()
{
Initialize();
}
private void Initialize()
{
if (mat != null)
{
return;
}
// 用 .material 生成独立实例,不影响材质资产
mat = GetComponent().material;
mat.SetFloat("_Progress", 0f);
transform.localScale = startScale;
}
///
/// 外部调用:石头人拳头砸到地面的那一帧触发
///
public void Play()
{
Initialize();
gameObject.SetActive(true);
timer = 0f;
mat.SetFloat("_Progress", 0f);
}
void Update()
{
if (timer < 0f) return;
timer += Time.deltaTime;
float progress = Mathf.Clamp01(timer / duration);
mat.SetFloat("_Progress", progress);
// 扩散结束自动隐藏
if (progress >= 1f)
{
gameObject.SetActive(false);
timer = -1f;
}
}
}
//(注:内容由AI生成)