How do I create multiple gameobjects linked to updating coordinates?

Hey,
Im currently working on a game for fun,
I’ve made it so that players can login, and that their x and z Position is saved in a database, and that these coordinates can be read out by other people.
link: My friend walking around

I am really close to having it show other people walking around, But the last part of the puzzle is to update (Maybe 5 times every second, it doesn’t have to be 100% smooth) the position of all the players in the array.

This is my current code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ShowOtherPlayers : MonoBehaviour {

	public bool MagUpdaten;
	public string[] users;
	public string Xpos;
	public string Ypos;

	// Use this for initialization

	void Start () {
		Invoke("StartUpdate", 2.5f);
	}

	void StartUpdate()
	{
		MagUpdaten = true;
	}


	void Update () {
		if (MagUpdaten) {
			StartCoroutine (SendData());
		}
	}


	IEnumerator SendData(){
		print ("Aan het Other Players updaten!");
		MagUpdaten = false;

		WWW userInfo = new WWW ("**WEBSITE HERE WITH PHP CODE TO EXTRACT INFO FROM DATABASE**");
		yield return userInfo;
		Debug.Log(userInfo.text);
		string userInfoString = userInfo.text;
		print ("online info: " + userInfoString);

		users = userInfoString.Split (';');
		Xpos = (GetDataValue(users[0], "Xpos:"));
		Ypos = (GetDataValue(users[0], "Ypos:"));

		yield return new WaitForSeconds (0.1f);
		MagUpdaten = true;
	}

	string GetDataValue(string data, string index){
		string value = data.Substring(data.IndexOf(index)+index.Length);
		if(value.Contains("|"))value = value.Remove(value.IndexOf("|"));
		return value;
	}
		
}

I am wondering if anyone can point me in the right direction to make this happen.
Maybe Instantiating on coordinates? im not sure how to do this.
Thanks :smiley:

Hey! Sorry, I don’t really understand what you still need. What I can see is that you have an array with all of the users in the game and the position of the player. So do you want to have the player appear on the screen? If so, what you would do is make something where each player in the array, in a for loop, would have an x and y pos set, and then for each player in the array you would instantiate a player at those coords. Then to update the player, say every 5 seconds, you would do an invoke repeating where it would get the updated coords, as before, and set the player in those coords. \

    for( int i = 0; i < users.Length; i++){
    users *<--- here you would split the array into the x and y*

GameObject player = <— here you would instantiate the player with the x and y coords you got InvokeRepeating(“Sample”, 5, 5, player, i);

}

void Sample(){
users <— here you would split the array into the x and y
player.transform.position = <— set the pos to the new x and y vals you got
}
This is untested, but it should work. Hopefully this helps! :smiley: