Beispiel #1
0
    private void OnReqFire(UserToken token, SocketModel model)
    {
        ReqFire req = SerializeUtil.Deserialize <ReqFire>(model.message);

        AccountData acc = CacheManager.instance.GetAccount(token.accountid);

        if (acc == null)
        {
            return;
        }
        Battle battle = CacheManager.instance.GetBattle(acc.battleid, acc.battleType);
        Tank   t      = battle.GetTank(token.accountid);

        if (t != null && t.hp > 0)
        {
            //校验两次攻击间隔
            if (Time.time * 0.001f - t.lastFireTime < 1)
            {
                return;
            }

            t.lastFireTime = Time.time * 0.001f;

            NotifyFire notify = new NotifyFire();
            notify.id  = token.accountid;
            notify.pos = req.pos;
            notify.rot = req.rot;

            MsgSender.SendOther <NotifyFire>(battle.accounts, token, (int)MsgID.NotifyFire, notify);
        }
    }
Beispiel #2
0
    public void UpDateInput(float dt)
    {
        float x = Input.GetAxis("Horizontal");
        float y = Input.GetAxis("Vertical");

        if (x != 0 || y != 0)
        {
            Vector3 dir = new Vector3(x, 0, y);

            //移动的趋势
            Vector3 dest = transfrom.position + dir * dt * speed;

            RaycastHit hit1;
            RaycastHit hit2;
            Vector3    origin = transfrom.position + new Vector3(0, 0.2f, 0);

            Vector3 direction = (dest - transfrom.position).normalized;
            if (Physics.Raycast(origin, transfrom.forward, out hit1, 1f) && Physics.Raycast(origin, direction, out hit2, 1f))
            {
            }
            else
            {
                //方向
                transfrom.forward = direction;
                //坐标
                transfrom.position = dest;

                ReqMove req = new ReqMove();
                req.pos = Tools.ToVec_3(transfrom.position);
                req.rot = Tools.ToVec_3(transfrom.eulerAngles);
                NetClient.instance.Send <ReqMove>((int)MsgID.ReqMove, req);
            }
        }
        //开火
        if (Input.GetMouseButton(0))
        {
            if (Time.time - lastFireTime >= cd)
            {
                //发射
                Fire(transfrom.position, transfrom.eulerAngles);

                ReqFire req = new ReqFire();
                req.pos = Tools.ToVec_3(transfrom.position + new Vector3(0, 1, 0));
                req.rot = Tools.ToVec_3(transfrom.eulerAngles);

                NetClient.instance.Send <ReqFire>((int)MsgID.ReqFire, req);
                lastFireTime = Time.time;
            }
        }
    }