Can anyone please give an example lines of code one could use to play/stop a VFX through C# script.
-
\$\begingroup\$ You should really be testing these methods yourself, which are all defined in the docs, and only then asking questions if things aren't working as you'd expect. You'll learn nothing by asking others to write code for you to copy-paste. \$\endgroup\$– arkonMar 19, 2020 at 2:30
1 Answer
Visual Effects API
https://docs.unity3d.com/2018.3/Documentation/ScriptReference/Experimental.VFX.VisualEffect.html
Stop Send a stop event to all Spawn systems.
Play Sends a stop event to all Spawn systems. If VisualEffect.resetSeedOnPlay is true, this methods recomputes a new random seed for the random value generator and resets internal total time to zero.
C# API
https://docs.unity3d.com/Packages/[email protected]/manual/index.html
using UnityEngine;
using UnityEngine.Experimental.VFX;
public class VFXTest : MonoBehaviour
{
public bool IsPlaying = true;
void Update()
{
if(Input.GetKeyDown(KeyCode.Space)){
IsPlaying = !IsPlaying;
}
if(IsPlaying){
GetComponent<VisualEffect>().Play();
}else{
GetComponent<VisualEffect>().Stop();
}
}
}
-
\$\begingroup\$ Thank you. I'll test it out soon... \$\endgroup\$ Jun 26, 2019 at 7:44