Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. using System;
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.IO;
  5. using System.Runtime.Serialization.Formatters.Binary;
  6. using System.Text;
  7. using UnityEngine.UI;
  8.  
  9. public class Player : MonoBehaviour {
  10.  
  11. private Guid mGuid;
  12. public Main main;
  13. private Transform thisTransform;
  14.  
  15. // Use this for initialization
  16. void Start () {
  17. thisTransform = transform;
  18. mGuid = Guid.NewGuid();
  19. }
  20.  
  21. // Update is called once per frame
  22. void Update () {
  23. if (!main.IsCaught())
  24. {
  25. Vector2 moveTransform = thisTransform.position;
  26. if (Input.GetKey(KeyCode.LeftArrow))
  27. {
  28. moveTransform.x -= 1 * Time.deltaTime;
  29. }
  30.  
  31. if (Input.GetKey(KeyCode.RightArrow))
  32. {
  33. moveTransform.x += 1 * Time.deltaTime;
  34. }
  35.  
  36. if (Input.GetKey(KeyCode.UpArrow))
  37. {
  38. moveTransform.y += 1 * Time.deltaTime;
  39. }
  40.  
  41. if (Input.GetKey(KeyCode.DownArrow))
  42. {
  43. moveTransform.y -= 1 * Time.deltaTime;
  44. }
  45.  
  46. thisTransform.position = moveTransform;
  47. }
  48. }
  49.  
  50. void OnCollisionEnter2D(Collision2D coll)
  51. {
  52. if(coll.gameObject.tag == "Player")
  53. main.Catch();
  54. }
  55.  
  56. public bool CheckGUID(string guid)
  57. {
  58. return guid.Equals(mGuid.ToString());
  59. }
  60.  
  61. public byte[] Serialize()
  62. {
  63. const string delim = ",";
  64. StringBuilder sb = new StringBuilder();
  65.  
  66. //Example:
  67. // U, guid , posX , posY
  68. //"U,2983465,100,80,5,90"
  69. sb.Append('U');
  70. sb.Append(delim);
  71.  
  72. sb.Append(mGuid);
  73. sb.Append(delim);
  74.  
  75. sb.Append(thisTransform.position.x);
  76. sb.Append(delim);
  77.  
  78. sb.Append(thisTransform.position.y);
  79. sb.Append(delim);
  80.  
  81. //return Encoding.Unicode.GetBytes(sb.ToString());
  82.  
  83. byte[] buffer = new byte[1024];
  84. Stream stream = new MemoryStream(buffer);
  85. BinaryFormatter formatter = new BinaryFormatter();
  86. formatter.Serialize(stream, sb.ToString());
  87. return buffer;
  88. }
  89.  
  90. public void Puppeteer(float posX, float posY)
  91. {
  92. thisTransform.position = new Vector2(posX, posY);
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement