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. Dismiss Notice

Best Way To Reset a Script Varibles

Discussion in 'Scripting' started by owiegand, Oct 26, 2014.

  1. owiegand

    owiegand

    Joined:
    Jan 20, 2014
    Posts:
    17
    In my game when a player is killed his model is turned off and turned back on when he respawns into the game, rather than destroying and instantiating the player every death. Right now I have reset methods in multiple scripts to reset the values of variables back to their default state each time the player respawns. Is there a better/cleaner way to do this same task?
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,377
    That's the best way I can think of.

    I'd make sure the name of the method is consistent. This way you could call it with SendMessage in one go.

    But having it like so is useful in case the state of the player changes what it resets to. Such as if you have a leveling system and depending the level is what the default values is. So you'd need to calculate this during the reset method.
     
  3. owiegand

    owiegand

    Joined:
    Jan 20, 2014
    Posts:
    17
    I completely forgot about SendMessage, being able to make only one call should reduce a few lines of code and the headache of making sure I have called every reset.