Created
December 9, 2024 14:50
-
-
Save SamyBencherif/89045e035d4f094d71d56ca9ff166c0c to your computer and use it in GitHub Desktop.
Plays effects made using Visual Effect Graph in Unity backwards
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.VFX; | |
public class VFXReverse : MonoBehaviour | |
{ | |
public float startTime = 5; | |
float time; | |
// Start is called once before the first execution of Update after the MonoBehaviour is created | |
void Start() | |
{ | |
//GetComponent<VisualEffect>().Stop(); | |
GetComponent<VisualEffect>().resetSeedOnPlay = false; | |
time = startTime; | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
const int iterations = 100; | |
if (time > 0) | |
{ | |
GetComponent<VisualEffect>().Reinit(); | |
for (int i = 0; i<iterations; i++) | |
GetComponent<VisualEffect>().Simulate(time/iterations); | |
time -= Time.deltaTime; | |
} | |
else if (time > -2) | |
{ | |
GetComponent<VisualEffect>().Reinit(); | |
time -= Time.deltaTime; | |
} | |
else | |
{ | |
time = startTime; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment