How to get game mode name to appear on the level?

I have two different game modes, and the player chooses one to play the game on. Both are buttons. The following script only gets you to level 1, it doesn’t show the word “endurance” on the level. How do I get it so it does show it? So, clicking that button would not only bring you to the level, but it will also say the game mode name as well.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

//Goes to level 1 after clicking Endurance Mode


public class endurance : MonoBehaviour
{
   
     public void EnduranceMode()
        {
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 2);

Create a Text UI element in the scene.

do I need to add code to that button?

No. if the text element is part of the new scene it will be in the scene when you load it. I would probably add code to the text to make it disappear after a few seconds, if that’s what you want.

but if I add two text objects in the scene, one for each game mode, wouldnt both show up no matter which game mode you chose?

I figured it out, I managed to use this (Set GUI Text active/inactive by clicking on a button? - Questions & Answers - Unity Discussions) as my guide to figure out how to make it work for me. But you are right, I did need the text objects in the level. I first tried to attach (therefore, made a new script) a script to the text object and also add new lines to my button script, but that didn’t work. So I deleted the script that was on my text object and instead only used the new lines that I added on my button script, and it worked. So for anyone else who wants something like this here you go:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

//Goes to level 1 after clicking Endurance Mode
//"Endurance Mode" will show up on each level when this button is clicked


public class endurance : MonoBehaviour
{
    public GameObject EnduranceText;



    void Start()
    {
        EnduranceText.SetActive(false);  //start text in level disabled
    }

    public void EnduranceMode()
{
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 2);

        if (EnduranceText.activeSelf)
        {
            EnduranceText.SetActive(true);
        }
        else
        {
            EnduranceText.SetActive(true);
        }

Btw, dont disable the text object in the level in its inspector panel, keep it enabled

@SuperCrow2 use caution because lines 27 and line 31 above are identical.

I know, that’s the only combination that worked for me lol.

Only problem is, since the button brings you to level 1, that script only works for level 1. Not sure how I can get the game mode name to show up on all levels after that one

You could look into additive scenes… basically you would have a “Level Announce” screen that would contain all the text and logic to turn the correct ones on and off, and you would load that additively with whatever level you’re playing.

That way you don’t end up retyping “Endurance Mode” into a text field in every single scene.

See the second argument:

That’s how you tell it that this scene is additive to whatever is already loaded. I break all my scenes into usefully diverse parts, like a preview screen, a UI portion, the main level content, lighting, the player, the enemies, etc.

And you can load all the scenes at once in the editor (drag them in) and work that way. You just cannot reference things from one scene to another, so you use variables and a common GameManager approach for stuff like that.

If you want another example, download the Unity TANKS! game… they have a large text level announce and results of match announce in there.

1 Like