Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

I don't know if this is the appropriate place to ask this

Discussion in 'UGUI & TextMesh Pro' started by LechongManok, Aug 16, 2019.

  1. LechongManok

    LechongManok

    Joined:
    Aug 16, 2019
    Posts:
    1
    Note to the admins and moderators of this forum: Sorry if I posted this on the wrong forum, as this is my FIRST TIME using Unity Forums. If this post is not appropriate in this section, please, admins and moderators, I hope that you will put it on the correct place. Thanks.

    I am using Unity for almost a month now and I am glad that I am learning something about UI Design (for our thesis, which I hope for the best) and using Unity overall. Although I cannot achieve the quality of Escape From Tarkov for now, I will get there.

    Now my question about UI Design is this - I have two buttons, in which I would like to redirect to one single scene. For example, I created two buttons, which I labeled as Experiment 1 and Experiment 2, respectively. These two buttons are expected to land on the next same scene I created, except that the text and the next scene (which is the AR part, where the experiment proper will be done) will be changed depending on what the user has pressed. I know that this can be done through creating another scene but the question is - what if we have 20+ buttons, you will have to create 20 scenes? That's not economical and a waste of time for me.

    So, I tried some coding, followed the tutorials that showed promise on solving my problem but alas, nothing is produced. The result? I am stuck on this dilemma at the last few days and I tried searching for an answer and up to now, I am still stuck. So, I decided to head to the forums to have the answers. Hope that you will help me.

    Thanks!
     
  2. Kirbyrawr

    Kirbyrawr

    Joined:
    Jul 23, 2012
    Posts:
    935
    First of all you don't need to use UIElements if you don't want.

    You can use this package that comes preinstalled in every project:
    https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/index.html

    Time to get dirty:
    - Set the UI Object (The parent that contains the buttons) as DontDestroyOnLoad (via script)
    - Attach the script to manage the buttons to UI Object.
    - When pressing a button, change the text and callbacks(OnClick) based on the button you touched (Experiment1, Experiment2)

    References:
    https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html
    https://docs.unity3d.com/Packages/c...UnityEngine.UI.Button.ButtonClickedEvent.html

    It sounds difficult but believe me that is not, check how to use dontdestroyonload and how to add callbacks to buttons, you don't need anything more.

    Maybe Unity Answers fits better for your question but i didn't want to leave you without the answer.
     
    Last edited: Aug 19, 2019
  3. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    631
    UIElements (relatively new UI framework) is not meant to be used for Runtime (in Playmode) at this time. We are still working on this ability. As @Kirbyrawr said, you're better off using uGUI (existing UI framework for runtime), which I assume you already are.

    As such, you'll have more luck with more answers on the uGUI forum. Moving thread.
     
unityunity