コード例 #1
0
    void Update()
    {
        weapon current_weapon = weapons[index];
        bool   shooting       = CrossPlatformInputManager.GetButton("Fire1");
        bool   drop           = CrossPlatformInputManager.GetButtonDown("Drop");
        float  scroll         = CrossPlatformInputManager.GetAxis("Mouse ScrollWheel");
        bool   reloading      = CrossPlatformInputManager.GetButtonDown("Reload");

        if (!photonView.isMine)
        {
            return;
        }
        if (reloading)
        {
            if (reload())
            {
                photonView.RPC("reload", PhotonTargets.All);
                time_since_last_shoot = -current_weapon.reload_time;
            }
        }
        if (current_weapon.auto)
        {
            shooting = CrossPlatformInputManager.GetButton("Fire1");
        }
        else
        {
            shooting = CrossPlatformInputManager.GetButtonDown("Fire1");
        }
        time_since_last_shoot += Time.deltaTime;
        if (shooting && time_since_last_shoot > current_weapon.get_fire_rate() && current_weapon.can_fire())
        {
            photonView.RPC("shoot", PhotonTargets.All);
            time_since_last_shoot = 0;
        }
        if (scroll > 0)
        {
            photonView.RPC("change_weapon", PhotonTargets.All, (index + 1) % weapons.Count);
        }
        else if (scroll < 0)
        {
            index = (index - 1) % weapons.Count;
            if (index < 0)
            {
                index = weapons.Count - 1;
            }
            photonView.RPC("change_weapon", PhotonTargets.All, index);
        }
        if (scroll != 0)
        {
            dc.ui.refresh_weapon();
        }
        if (drop)
        {
            photonView.RPC("drop_weapon", PhotonTargets.All);
            dc.ui.refresh_weapon();
        }
    }