Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    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:
    65
    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:
    32,305
    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:
    65
    Thanks. I'll do some research.