Forum rules - please read before posting.

How do i turn on and off a script through the menu?

Im kind of new to unity, scripting, and Adventure Creator as well, keep that in mind haha.

Anyways, i made an advanced settings menu, and i want to be able to turn on and off camera effect scripts in that menu. Or if not turn off the scripts completely, toggle off some of the effects.

Not sure how to go forward from here. 

imageimageimage

Comments

  • Welcome to the community, @michlon.

    The best way to tackle this would be to use your Toggle to control the value of a Global Bool Variable, which in turn determines whether or not a particular effect should be enabled.

    Basically, you create a new Global Bool in the Variables Manager, then back in your Menu set the Toggle type to Variable, and then set the Global boolean var field beneath to your new variable.

    You can then also assign an ActionList on click asset that runs when the user changes its value.  You can use the Variable: Check Action to read the Variable's new value and disable/enable the relevent component accordingly.

    That will take a custom script, and isn't AC-related, but it's essentially somthing like this:

    public void DisableSunShafts ()
    {
      Camera.main.GetComponent <SunShafts>().enabled = false;
    }

    public void EnableSunShafts ()
    {
      Camera.main.GetComponent <SunShafts>().enabled = true;
    }

    To trigger these functions, place these in a new C# script, add the component to a new GameObject and then make that GameObject a prefab.  You can then use the Object: Call event Action to trigger the relevant functions within the prefab.

    It's also possible to have this update with your options data along with e.g. music volume - see this tutorial.
  • Ah thanks alot! Been stuck on how to do this for some time now :P
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.