gpt4 book ai didi

c# - 使用数据库中的数据实例化对象会更改值

转载 作者:行者123 更新时间:2023-11-29 15:48:00 25 4
gpt4 key购买 nike

我正在开发一款基于位置的游戏,该游戏在 map 上显示每个玩家的位置。

因此每个客户端都会将纬度、经度和他的玩家名上传到 MySQL 数据库。检索查询并将值拆分为数组后,每个玩家的标记都会成功加载到其正确位置,但他们的玩家名称会切换到下一个标记。

public  void CreatePlayerAvatars()
{
GameObject[] allObjects = GameObject.FindGameObjectsWithTag("PlayerMarker");
foreach(GameObject obj in allObjects) {
Destroy(obj);
}
float worldScale = FindObjectOfType<AbstractMap>().WorldRelativeScale;
Vector2d mapCenter = FindObjectOfType<AbstractMap>().CenterMercator;
if (PlayerGeoLocation != null && PlayerGeoLocation.text.Length > 0 )
{
// data from db
string data = playerDataString.Replace(",",".");

string[] datasets = data.Split('¡');

try
{
foreach(string item in datasets)
{

string[] Itemdata = item.Split('œ');

string id = Itemdata[0];
print(id);
string name = Itemdata[1];
print("name "+name);
string Lat = Itemdata[2];
print("lat: "+Lat);
string Lon = Itemdata[3];
print("Lon: " + Lon);

PlayerLat = Convert.ToDouble(Lat, System.Globalization.CultureInfo.InvariantCulture);
PlayerLon = Convert.ToDouble(Lon, System.Globalization.CultureInfo.InvariantCulture);


Vector3 InstancePosition = Conversions.GeoToWorldPosition(PlayerLat, PlayerLon, mapCenter, worldScale).ToVector3xz(); // This needs a reference point!

Instantiate(PlayerMarker, InstancePosition, Quaternion.identity );

PlayerLable = PlayerMarkerCanvas.GetComponent<Text>();
PlayerLable.text = name;}} catch()}}

没有错误消息,只是切换器..

如果有人有提示,我们将不胜感激。感谢您抽出时间

最佳答案

我真傻。我在实例化后添加了标签文本。

关于c# - 使用数据库中的数据实例化对象会更改值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56936201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com