- Home /
instance and static variables
I am creating a beanbag toss game and want each player to get 3 tosses, so I need to keep track of these in a static variable. When I instantiate the beanbag, I only want the active beanbag to get tossed.
Should I create a player game object that just keeps track of the number of throws so I can create a static variable or is there some way to do this in a script that is part of the beanbag itself?
Thanks
Answer by Ricardo · Jun 28, 2010 at 07:44 AM
Seems that you have two separate issues here.
First, you only want a beanbag to be used once - you toss it, and it ends up somewhere in the ground and stays there. That would be specific to the state of your beanbag item, so you could handle it there, and it wouldn't allow the player to select it after they've tossed it.
Second, you want to track the number of throws, and I would imagine other game information as well (for instance, the score). This you could just track on a single game object representing your player, which would be the one controlling the game state.
Your answer
![](https://koobas.hobune.stream/wayback/20220613063234im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Would setting this static cause a memory leak? 1 Answer
An instance of type X is required to access non static member Y [javascript] 4 Answers
how do I create a static Instance in javascript 2 Answers
Singleton instance accessed in coroutine always null 1 Answer
Help with Error: An instance of type 'Regex' is required to access non static member 'Replace'. 2 Answers