Пример #1
0
    // Update is called once per frame
    void Update()
    {
        string rawData = null;

        while (m_recvMsgs.Count > 0)
        {
            rawData = m_recvMsgs.Dequeue();
            OnRecieveMsg(rawData);
        }

        if (m_myCreature == null)
        {
            return;
        }

        if (Input.GetMouseButtonUp(0))
        {
            Vector3 v3 = Input.mousePosition;
            v3.z = 10.0f;
            v3   = Camera.main.ScreenToWorldPoint(v3);
            v3.y = 0;

            Protocol.MoveReq req = new Protocol.MoveReq();
            req.goal = v3;

            ws.Send(JsonMapper.ToJson(req));
        }

        if (Input.GetKeyUp(KeyCode.Space))
        {
            Vector3 v3 = Input.mousePosition;
            v3.z = 10.0f;
            v3   = Camera.main.ScreenToWorldPoint(v3);
            v3.y = 0;

            Vector3 dir = (v3 - m_myCreature.transform.position).normalized;
            Protocol.FireBulletReq req = new Protocol.FireBulletReq();
            req.dir = dir;

            ws.Send(JsonMapper.ToJson(req));
        }
    }
Пример #2
0
	// Update is called once per frame
	void Update () {
		string rawData = null;

		while (m_recvMsgs.Count > 0) {
			rawData = m_recvMsgs.Dequeue();
			OnRecieveMsg (rawData);
		}

		if (m_myCreature == null)
			return;

		if (Input.GetMouseButtonUp (0)) {
			
			Vector3 v3 = Input.mousePosition;
			v3.z = 10.0f;
			v3 = Camera.main.ScreenToWorldPoint(v3);
			v3.y = 0;

			Protocol.MoveReq req = new Protocol.MoveReq();
			req.goal = v3;

			ws.Send(JsonMapper.ToJson(req));
		}

		if (Input.GetKeyUp (KeyCode.Space)) {

			Vector3 v3 = Input.mousePosition;
			v3.z = 10.0f;
			v3 = Camera.main.ScreenToWorldPoint(v3);
			v3.y = 0;

			Vector3 dir = (v3-m_myCreature.transform.position).normalized;
			Protocol.FireBulletReq req = new Protocol.FireBulletReq();
			req.dir = dir;
			
			ws.Send(JsonMapper.ToJson(req));
		}
	}