6
\$\begingroup\$

Can anyone please give an example lines of code one could use to play/stop a VFX through C# script.

\$\endgroup\$
1
  • \$\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\$
    – arkon
    Mar 19, 2020 at 2:30

1 Answer 1

4
\$\begingroup\$

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/com.unity.visualeffectgraph@6.7/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();
        }
    }
}
\$\endgroup\$
1
  • \$\begingroup\$ Thank you. I'll test it out soon... \$\endgroup\$ Jun 26, 2019 at 7:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .