Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- using System.Collections;
- using System.IO;
- using System.Runtime.Serialization.Formatters.Binary;
- using System.Text;
- using UnityEngine.UI;
- public class Player : MonoBehaviour {
- private Guid mGuid;
- public Main main;
- private Transform thisTransform;
- // Use this for initialization
- void Start () {
- thisTransform = transform;
- mGuid = Guid.NewGuid();
- }
- // Update is called once per frame
- void Update () {
- if (!main.IsCaught())
- {
- Vector2 moveTransform = thisTransform.position;
- if (Input.GetKey(KeyCode.LeftArrow))
- {
- moveTransform.x -= 1 * Time.deltaTime;
- }
- if (Input.GetKey(KeyCode.RightArrow))
- {
- moveTransform.x += 1 * Time.deltaTime;
- }
- if (Input.GetKey(KeyCode.UpArrow))
- {
- moveTransform.y += 1 * Time.deltaTime;
- }
- if (Input.GetKey(KeyCode.DownArrow))
- {
- moveTransform.y -= 1 * Time.deltaTime;
- }
- thisTransform.position = moveTransform;
- }
- }
- void OnCollisionEnter2D(Collision2D coll)
- {
- if(coll.gameObject.tag == "Player")
- main.Catch();
- }
- public bool CheckGUID(string guid)
- {
- return guid.Equals(mGuid.ToString());
- }
- public byte[] Serialize()
- {
- const string delim = ",";
- StringBuilder sb = new StringBuilder();
- //Example:
- // U, guid , posX , posY
- //"U,2983465,100,80,5,90"
- sb.Append('U');
- sb.Append(delim);
- sb.Append(mGuid);
- sb.Append(delim);
- sb.Append(thisTransform.position.x);
- sb.Append(delim);
- sb.Append(thisTransform.position.y);
- sb.Append(delim);
- //return Encoding.Unicode.GetBytes(sb.ToString());
- byte[] buffer = new byte[1024];
- Stream stream = new MemoryStream(buffer);
- BinaryFormatter formatter = new BinaryFormatter();
- formatter.Serialize(stream, sb.ToString());
- return buffer;
- }
- public void Puppeteer(float posX, float posY)
- {
- thisTransform.position = new Vector2(posX, posY);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement