Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How can I do this?

Discussion in 'World Building' started by Noodle_Meanie, Jan 21, 2023.

  1. Noodle_Meanie

    Noodle_Meanie

    Joined:
    Sep 11, 2021
    Posts:
    110
    I've been making a game and, in the game's lobby I have a trigger that will send you to another scene. Now, I need a way to have something that will make it so that it sends the player to one of many scenes 49 times, then have the 50th time send you to a specific scene, then another 49 times and the 100th be specific. Anyone know a way to do this? Remember there are some scenes I never want it to transition to, and that I want many possibilities. Thanks.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,298
    You need a persistent counter that you increment at each "played level," whatever that means for you.

    Then before you choose to load a level, you compare that to 50, or compare to 100, and take appropriate action.

    If you want it for EVERY level divisible by 50, use the modulo operator (
    %
    ) and check the remainder for being zero.

    Code (csharp):
    1. if ((yourAge % 7) == 0)
    2. {
    3.   Debug.Log( "Your age is divisible by 7!");
    4. }
    NOTE: "persistent counter" in your case may mean something stored in PlayerPrefs alongside other saved user progress like score, or it could be less-persistent, such as only kept for the game duration.
     
  3. Noodle_Meanie

    Noodle_Meanie

    Joined:
    Sep 11, 2021
    Posts:
    110
    Thanks. I'll do some research.