Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

consequence story

Discussion in 'Game Design' started by Venomwolf, Oct 25, 2018.

  1. Venomwolf

    Venomwolf

    Joined:
    Feb 6, 2017
    Posts:
    1
    so im working on a story where the player has a finite amount of troops after a certain point. if they lose units, in later levels, they should have the same amount as the ones that survived before. does anyone know how i can set this up cross-scenes?
     
  2. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,083
    Just keep a list of troops internally and don't let them deploy ones that have an isDead flag set.
     
  3. Magician_Arcana

    Magician_Arcana

    Joined:
    Aug 23, 2015
    Posts:
    47
    Yeah for something like this I would make a global variables object that uses the dontDestroyOnLoad method and contains values that can be accessed in any scene. Give the object like a "troopsCount" value that's updated when you lose troops and checked at the beginning of each level to know how many troops to spawn.

    Or rather than a count, a list of your troop GameObjects if that's how you wanna treat it.

    https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html
     
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Scene additive loading may be useful, as all units could be simply stored as a part of different scene.
     
  5. newjerseyrunner

    newjerseyrunner

    Joined:
    Jul 20, 2017
    Posts:
    966
    I have a similar system for my coop mode. I create all of the characters off the bat in my menu scene then call DontDestroyOnLoad. If the player logs out during the game, I simply disable the character with SetActive(false)
     
  6. JennyHide

    JennyHide

    Joined:
    Sep 30, 2014
    Posts:
    47