- Home /
Object being created with last info
alright so im creating an object and its being created but theres a problem when its created it works but when i change something in the database i restart the game and it doesnt change i have to restart twice for it to change
this is the code that makes the object
using UnityEngine; using TMPro; using System.Collections; using UnityEngine.Networking; using UnityEngine.UI; using UnityEngine.SceneManagement; using System.Collections.Generic;
public class getInv : MonoBehaviour { [SerializeField] private string getinvEndpoint = "";
[SerializeField] private string usernamer;
[SerializeField] private string slot;
[SerializeField] private string slotnum;
[SerializeField] private string[] items;
public GameObject ItemGui;
public GameObject slot1;
public GameObject slot2;
public GameObject slot3;
public GameObject slot4;
public GameObject slot5;
public GameObject slot6;
public GameObject slot7;
public GameObject theslot;
public bool is1;
public bool is2;
public bool is3;
public bool is4;
public bool is5;
public bool is6;
public bool is7;
public void Start()
{
StartCoroutine(TrygetInv());
}
public IEnumerator TrygetInv()
{
string username = usernamer;
WWWForm form = new WWWForm();
form.AddField("rUsername", username);
UnityWebRequest request = UnityWebRequest.Post(getinvEndpoint, form);
yield return request.SendWebRequest();
float startTime = 0.0f;
while (!request.isDone)
{
startTime += Time.deltaTime;
if (startTime > 10.0f)
{
break;
}
yield return null;
}
if (request.result == UnityWebRequest.Result.Success)
{
InventoryResponse response = JsonUtility.FromJson<InventoryResponse>(request.downloadHandler.text);
Debug.Log(request.downloadHandler.text);
Debug.Log(response.arraytest);
string temp = (response.arraytest);
string[] split;
string[] seperators = { (":") };
split = temp.Split(seperators, System.StringSplitOptions.None);
foreach (var member in split)
{
if (member != "")
{
string testing = member;
string[] Ending;
string[] Keepaways = { ("-") };
Ending = testing.Split(Keepaways, System.StringSplitOptions.None);
slotnum = Ending[3];
Debug.Log(slotnum);
Instantiate(ItemGui);
ItemSetups iteminfo = ItemGui.GetComponent<ItemSetups>();
iteminfo.id = Ending[0];
iteminfo.objname = Ending[1];
iteminfo.amount = Ending[2];
iteminfo.slot = slotnum;
iteminfo.slotObj = theslot;
}
}
} else
{
Debug.Log("error connecting to inv");
}
yield return null;
}
}
This is the code on the object
using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; using UnityEngine.UI;
public class ItemSetups : MonoBehaviour { public Sprite One; public Sprite Two; public string id; public string objname; public string amount; public string slot;
public GameObject slotObj;
public TMP_Text Names;
public TMP_Text Amount;
public Image Logo;
public void Update()
{
if(id == "1")
{
Logo.sprite = One;
} else if (id == "2")
{
Logo.sprite = Two;
} else
{
}
Names.text = objname;
Amount.text = amount;
}
public void Start()
{
gameObject.transform.SetParent(slotObj.transform, false);
}
}
the console log is said correctly its just the creation that is wrong