Beispiel #1
0
    void Update()
    {
        if (!PhotonNetwork.IsMasterClient || null == _bot)
        {
            return;
        }
        if (!_isMasterClient)
        {
            _isMasterClient = true;
            _pointIndex     = GetClosestPointIndex(_route, transform.position);
            _routePoint     = _route.GetChild(_pointIndex).position;
            _bot.Patrol(_routePoint);
            if (null == _weapon)
            {
                PhotonNetwork.CurrentRoom.SetBotHealth(photonView.ViewID, GameSetting.Instance.MaxHealth);
                photonView.RPC(GameConst.RpcEquip, RpcTarget.All, Random.Range(0, GameSetting.Instance.Weapons.Count));
            }
        }

        if (_shootTimer > 0)
        {
            _shootTimer -= Time.deltaTime;
        }
        else if (_canShoot)
        {
            _shootTimer = _weapon.FireRate;
            photonView.RPC(GameConst.RpcShoot, RpcTarget.All);
        }

        if (_lockTimer > 0)
        {
            _lockTimer -= Time.deltaTime;
            if (_lockTimer <= 0)
            {
                _bot.transform.rotation = Quaternion.LookRotation(_routePoint - _bot.transform.position);
                _bot.Patrol(_routePoint);
            }
        }
        else if (Vector3.Distance(_bot.transform.position, _routePoint) < 2f)
        {
            _pointIndex = _route.childCount > _pointIndex + 1 ? _pointIndex + 1 : 0;
            _routePoint = _route.GetChild(_pointIndex).position;
            _bot.Patrol(_routePoint);
        }
    }