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.

Spawn new object same code but different code?

Discussion in '2D' started by Afrokid001, Jan 30, 2014.

  1. Afrokid001

    Afrokid001

    Joined:
    Jun 3, 2010
    Posts:
    89
    Hi guys,

    I have a button that spawns an object with a few variables.

    It has Hunger, Experience, Level and Health. When I click said button, it spawns the object.. Good! but when I click it again, it spawns a clone of the first which will inherit the code from the first?

    So if I feed the first, or let it get low, the second one is just as hungry as the first instead of spawning at its full hunger.

    How would I get around this?

    I'm using an instantiate code.
     
  2. wccrawford

    wccrawford

    Joined:
    Sep 30, 2011
    Posts:
    2,038
    Stop using static variables.
     
  3. Afrokid001

    Afrokid001

    Joined:
    Jun 3, 2010
    Posts:
    89
    I tried that earlier but it kept coming up saying it needed to be a static to be changed? The exact error was "BCE0020: An instance of type 'Feeder' is required to access non static member 'Hunger'.".

    Oh, I didn't realize I posted in the 2D forum, I must of clicked the wrong link while I was browsing.