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\$ Mar 19 '20 at 2:30
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\$
    – MetaMax
    Jun 26 '19 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.