How to structure my varibles?

Hi,
I’m trying to have an tree grow, until you cut it down for wood.

I have a button (ButtonCreateTree) that instantiates a prefab.
When this prefab is instantiated, a counter starts.
When the counter reaches 30, a button is instantiated (CutTreeButton).
When you click the button, the prefab is destroyed.

I also want another variable, (count).
When I press the ButtonCreateTree the count goes +1, when I press CutTreeButton, the count goes -1.

The only problem is I don’t know where to instantiate the variable in order to be able to access it from both buttons, and modify it.You can take a look at my graph:


Thanks!

Maybe a couple of ways to do that.

  • You could put the “main count” (let’s name ‘globalCount’) as a public variable in a component of ButtonCreateTree. In this way you could get (searching by Tags, Name, etc) that component from every TreeWithCycle instance and then access to the ‘globalCount’
  • You could define a scene main component and define the variable as a member of this component and then access from ButtonCreateTree and ButtonCutTree in the same way as above.