- Home /
getting a GameObject array of all the connected players
Hello everyone, I am makeing a proceduraly generated terrain for a multiplayer game that will hopefully allow miles and miles of terrain to explore. up to now i have a script that can create a series of seamless chunks at a certain point, but i am missing a way to get an array of all the players' positions. I have tried a few ways but its been basicaly throwing shit at the wall to see what sticks. If you guys have any idea on how to do this pls tell me. thanks to all of you.
are you using Photon or standard Unity networking? if you need just the positions you can give a tag to the player prefab. so after instantiating you could get them into a GameObject[] array with GameObject.FindGameObjectsWithTag("Player");
.
Answer by LT23Live · May 02, 2015 at 12:55 AM
Make a variable
public GameObject[] players;
if all players start at the same time. in your void Start () type the line players = GameObject.FindGameObjectsWithTag ("Player"); if they log in and out, put that line in void Update ().
to access each GameObject just write in your update or a function/coroutine foreach (GameObject go in players)
then set it to do whatever. just make sure to reference each one as 'go' in that function not 'players'
Your answer
Follow this Question
Related Questions
Multiplayer game, terrain edit control for 2 characters 0 Answers
unity game 1 Answer
Camera rotation around player while following. 6 Answers