- Home /
Switching Trough Active Players using Lists
I have a List with all Players in the level. Every Object has a bool called: "ActivePlayer" and not in every Object is "Active Player" set to true. I want to be able to "possess" every object in that list that has it true. so I have an empty wich should always move to the main Player. I would input into the Empty the "selected Object". so Now is there a way to switch trough every object in that List with "ActivePlayer" on where it would also loop at the start and the end of that list?
Answer by logicandchaos · Feb 23, 2020 at 10:39 PM
Yes, you can use a list rather than a bool, the bool method would allow for multiple active players, but you can use a list of players and then a player variable that could be set to one from your list.
List<Player> players;
Player activePlayer;
Then you can all the Players to that List, I would do that in the Player script in Start or OnEnable, but check to make sure it hasn't been added yet, then you can remove it in OnDIsable() or OnDestroy().
this already helped but I'm planning on having multiple players of which I can only possess the ones with the bool "active". so I would have 2 bools one set to "isPossesable" and the other to "isActive" if you don't understand don't worry I'm pretty bad at explaining :D
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
question about array or list of boolean 1 Answer
List of bools with names 1 Answer
Switching from GameObject to GameObject by using a list 1 Answer
Bool always returning true even if should return false. 0 Answers