Advertisement
Guest User

Untitled

a guest
Jun 26th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. //method I am currently using
  2. Scrollbar.GetComponent<Scrollbar>().value = -1f
  3.  
  4. //this method appears to update the canvas but kills functionality of the scrollbar
  5. Scrollrect.GetComponent<ScrollRect>().verticalNormalizedPosition = 0.5f;
  6.  
  7. void Update ()
  8. {
  9. //querying database every 3 seconds so doesnt flood host while testing
  10. if(Time.time >= nextUpdate)
  11. {
  12. nextUpdate = Mathf.FloorToInt(Time.time)+3;
  13. if (LastMessageID == null) { StartCoroutine(getLastMessageIDfromDB()); }
  14. else {getLobbyChatMessage ();}
  15. }
  16. }
  17.  
  18.  
  19. public void getLobbyChatMessage ()
  20. {
  21. StartCoroutine(getLobbyChat(0, "Public", LastMessageID));
  22. }
  23.  
  24. public IEnumerator getLobbyChat (int game_id, string channel, string LastMessageID)
  25. {
  26. WWWForm newForm = new WWWForm ();
  27. newForm.AddField ("game_id", game_id); //post data sent to php
  28. newForm.AddField ("channel", channel);//post data sent to php
  29. newForm.AddField ("LastMessageID", LastMessageID);//post data sent to php
  30. WWW w = new WWW (getChatURL, newForm);
  31. while (!w.isDone) { yield return w;}
  32. if (w.error != null) { Debug.Log("There was a problem getting info:" + w.error); }
  33. else
  34. {
  35. result = w.text;
  36. values = result.Split("|"[0]);
  37. if (values.Length >= 1)
  38. {
  39. for (int i = 0; i < (values.Length - 1); i++)
  40. {
  41. string cleanedMessage = WWW.UnEscapeURL(values[4]).ToString();
  42. myNewMessage = Instantiate(NewMessagePrefab, transform.position, Quaternion.identity) as GameObject;
  43. myNewMessage.transform.SetParent(ChatParent);
  44. newMessage = myNewMessage.GetComponent<Text>();
  45. newMessage.text = "[" + values[5] + "]" + "[" + values[3] + "] " + cleanedMessage;
  46. myNewMessage.name = "[" + values[5] + "]" + "[" + values[3] + "] " + cleanedMessage;
  47. }
  48. Scrollbar.GetComponent<Scrollbar>().value = -1f;
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement