// Start is called before the first frame update void Start() { NetManaager.AddListener("Enter", OnEnter); NetManaager.AddListener("OnMove", OnMove); NetManaager.AddListener("OnLeave", OnLeave); NetManaager.Connect("127.0.0.1", 8080); //添加一个角色 GameObject obj = (GameObject)Instantiate(humanPrefab); float x = Random.Range(-5, 5); float z = Random.Range(-5, 5); obj.transform.position = new Vector3(x, 1, z); myhuman = obj.AddComponent <CtrlHuman>(); myhuman.desc = NetManaager.GetDesc(); //发送协议 Vector3 pos = myhuman.transform.position; Vector3 eul = myhuman.transform.eulerAngles; string sendStr = "Enter|"; sendStr += NetManaager.GetDesc() + ","; sendStr += pos.x + ","; sendStr += pos.y + ","; sendStr += pos.z + ","; sendStr += eul.y; NetManaager.Send(sendStr); }
// Update is called once per frame new void Update() { base.Update(); if (Input.GetMouseButton(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hits; Physics.Raycast(ray, out hits); if (hits.collider.tag == "Terrain") { MoveTo(hits.point); NetManaager.Send("Enter|127.1.1.1,200,300,400,45"); } } }