- Home /
Instantiating for every Xpos and Zpos
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 :D
I'm not exactly sure what you are trying to do. There is already a 'Network Transform' component if you take a look at UNet. https://docs.unity3d.com/$$anonymous$$anual/class-NetworkTransform.html