Search Unity

How to bring toggle input to a new scene

Discussion in 'UGUI & TextMesh Pro' started by BigEScherer, Jan 28, 2020.

  1. BigEScherer

    BigEScherer

    Joined:
    Aug 20, 2019
    Posts:
    7
    Hi there - I'm trying to let a user input his name, and when they hit a submit button, it will display the name in the next scene. The only wrinkle is before they hit Submit on the first screen, they have the option to have their name flashing by hitting a toggle button.

    I'm new to Unity and I'm tearing my hair out on this one! Thanks for any help!
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi and welcome @BigEScherer,

    What exactly is your problem, can you elaborate? Do you have trouble adding a toggle button or what is causing you some issues? You mention "the next scene", do you mean with this that you load another scene when user hits a submit button? Please be more specific. Code would be good too so that we can help you.
     
    BigEScherer likes this.
  3. BigEScherer

    BigEScherer

    Joined:
    Aug 20, 2019
    Posts:
    7
    Thanks for your reply! I've tried to simplify the "toggle test" since my last post.

    My first scene simply has a button and a toggle, labeled "flashing." If the user checks the toggle box (meaning "flashing" is on) and then clicks the submit button, the next scene loads with a square that is flashing on and off. If the toggle is not checked, the user clicks the submit button and the next scene loads with the square just sitting there, not flashing. Very simple, but I'm not having any luck. Here is my C# code:
    ------
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    using UnityEngine.SceneManagement;

    public class TestSettings : MonoBehaviour
    {

    public GameObject square;

    public float timer;

    public void Toggle_Changed(bool newValue)
    {
    Debug.Log(newValue);
    }

    public void OnSubmit()
    {

    Debug.Log("Launch square scene ");

    SceneManager.LoadScene(1);
    }

    // Start is called before the first frame update
    void Start()
    {

    }

    void Update()

    {

    if (newValue) [this variable isn't allowed down here under Update(). Not sure why]

    {

    timer += Time.deltaTime;

    if (timer >= 0.5)
    {
    square.gameObject.SetActive(true);

    }

    if (timer >= 1)
    {

    square.gameObject.SetActive(false);

    timer = 0;
    }
    }

    }
    }
    ----------
    Okay, obviously this code doesn't work. But I've tried all kinds of different approaches, including putting methods down under Update() like this:

    public void Toggle_Changed(bool newValue)
    { blah blah flash the square
    }

    but I get an error as soon as I type in "public." Strange, since I've seen other examples where that's allowed. I think I've got everything linked properly in Unity, but nothing has worked.

    Thanks for any help! I've been stuck on this for way too long!