using UnityEngine; using UnityEngine.VFX; [ExecuteInEditMode] public class MoveWave : MonoBehaviour { public bool autoplay = true; [Range(0f, 1f)] public float stateOverride; public float speedWave = 1f; public Vector2 positions = new Vector2(-100f, 0f); public Material deformer; public VisualEffect vfxLip; internal float startTime; private void Start() { startTime = Time.realtimeSinceStartup; } private void Update() { float state = GetState(); if (vfxLip != null) { vfxLip.SetFloat("_factorWave", state); } if (deformer != null) { deformer.SetFloat("_State", state * 2f); } base.transform.position = new Vector3(Mathf.Lerp(positions.x, positions.y, state), 0f, 0f); if (state > 1f) { startTime = Time.realtimeSinceStartup; } } public float GetState() { if (!autoplay) { return stateOverride; } return (Time.realtimeSinceStartup - startTime) / speedWave; } }