Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //method I am currently using
- Scrollbar.GetComponent<Scrollbar>().value = -1f
- //this method appears to update the canvas but kills functionality of the scrollbar
- Scrollrect.GetComponent<ScrollRect>().verticalNormalizedPosition = 0.5f;
- void Update ()
- {
- //querying database every 3 seconds so doesnt flood host while testing
- if(Time.time >= nextUpdate)
- {
- nextUpdate = Mathf.FloorToInt(Time.time)+3;
- if (LastMessageID == null) { StartCoroutine(getLastMessageIDfromDB()); }
- else {getLobbyChatMessage ();}
- }
- }
- public void getLobbyChatMessage ()
- {
- StartCoroutine(getLobbyChat(0, "Public", LastMessageID));
- }
- public IEnumerator getLobbyChat (int game_id, string channel, string LastMessageID)
- {
- WWWForm newForm = new WWWForm ();
- newForm.AddField ("game_id", game_id); //post data sent to php
- newForm.AddField ("channel", channel);//post data sent to php
- newForm.AddField ("LastMessageID", LastMessageID);//post data sent to php
- WWW w = new WWW (getChatURL, newForm);
- while (!w.isDone) { yield return w;}
- if (w.error != null) { Debug.Log("There was a problem getting info:" + w.error); }
- else
- {
- result = w.text;
- values = result.Split("|"[0]);
- if (values.Length >= 1)
- {
- for (int i = 0; i < (values.Length - 1); i++)
- {
- string cleanedMessage = WWW.UnEscapeURL(values[4]).ToString();
- myNewMessage = Instantiate(NewMessagePrefab, transform.position, Quaternion.identity) as GameObject;
- myNewMessage.transform.SetParent(ChatParent);
- newMessage = myNewMessage.GetComponent<Text>();
- newMessage.text = "[" + values[5] + "]" + "[" + values[3] + "] " + cleanedMessage;
- myNewMessage.name = "[" + values[5] + "]" + "[" + values[3] + "] " + cleanedMessage;
- }
- Scrollbar.GetComponent<Scrollbar>().value = -1f;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement