示例#1
0
        private void Update()
        {
            //take storm and water damage only on the master client
            if (!PhotonNetwork.isMasterClient)
            {
                return;
            }

            timer += Time.deltaTime;

            //apply damage to player in the storm
            if (inStorm)
            {
                if (timer > waitingTime)
                {
                    TakeDamage(StormManagerScript.GetInstance().stormDmg);
                    timer = 0f;
                }
            }

            //apply damage to player in the water
            if (inWater)
            {
                Debug.Log("IN WATER, TAKE DAMAGE");
                //insta death when the player touches the water
                TakeDamage(300);
            }
        }
示例#2
0
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
 }
示例#3
0
        private void Update()
        {
            isInPause = GameManagerScript.GetInstance().IsGamePause();

            if (photonView.isMine && GameManagerScript.canPlayerMove)
            {
                if (Input.GetKeyDown(KeyCode.Escape))
                {
                    GameManagerScript.GetInstance().PauseLogic();
                }
            }

            if (isInPause || !GameManagerScript.canPlayerMove)
            {
                //stop sound when in pause
                if (audioSource.isPlaying)
                {
                    audioSource.Stop();
                }

                return;
            }

            if (!photonView.isMine)
            {
                return;
            }

            bool isAltPressed = Input.GetKey(KeyCode.LeftAlt);

            //update alive number on change
            if (GameManagerScript.alivePlayerNumber != previousAliveNumber)
            {
                uiScript.UpdateAliveText(GameManagerScript.alivePlayerNumber);
                previousAliveNumber = GameManagerScript.alivePlayerNumber;
            }

            //update the storm timer in the UI
            if (StormManagerScript.GetInstance().GetStormTimer() >= 0)
            {
                uiScript.UpdateStormTimer(StormManagerScript.GetInstance().GetStormTimer());
            }

            if (Input.GetButtonDown("Fire2"))
            {
                Cursor.lockState = CursorLockMode.Locked;
                Cursor.visible   = false;
            }

            if (Input.GetButtonDown("Fire1"))
            {
                if (weaponHolder.currentWeapon != null)
                {
                    var weapon = weaponHolder.currentWeapon;

                    if (weapon && weapon.CanFire())
                    {
                        //send shot request to all
                        photonView.RPC("ShootRPC", PhotonTargets.AllViaServer, playerID);
                    }
                }

                if (consommableHolder.currentConsommable != null)
                {
                    var consommable = consommableHolder.currentConsommable;

                    // - cancel use if the player is full life
                    var cancel_use = (consommable.GetHealth() > 0 && consommable.GetShield() == 0 && photonView.GetHealth() == PlayerStats.maxHealth);
                    cancel_use = cancel_use || (consommable.GetShield() > 0 && consommable.GetHealth() == 0 && photonView.GetShield() == PlayerStats.maxShield);

                    if (!cancel_use)
                    {
                        photonView.RPC("ShootRPC", PhotonTargets.AllViaServer, playerID);
                    }
                }
            }

            if (Input.GetKeyDown(CustomInputManagerScript.keyBind["Slot1"]))
            {
                if (isAltPressed)
                {
                    playerInventory.SwapInventorySlot(currentIndex, 0);
                }

                else
                {
                    index = 0;
                }
            }
            else if (Input.GetKeyDown(CustomInputManagerScript.keyBind["Slot2"]))
            {
                if (isAltPressed)
                {
                    playerInventory.SwapInventorySlot(currentIndex, 1);
                }

                else
                {
                    index = 1;
                }
            }
            else if (Input.GetKeyDown(CustomInputManagerScript.keyBind["Slot3"]))
            {
                if (isAltPressed)
                {
                    playerInventory.SwapInventorySlot(currentIndex, 2);
                }

                else
                {
                    index = 2;
                }
            }
            else if (Input.GetKeyDown(CustomInputManagerScript.keyBind["Slot4"]))
            {
                if (isAltPressed)
                {
                    playerInventory.SwapInventorySlot(currentIndex, 3);
                }

                else
                {
                    index = 3;
                }
            }
            else if (Input.GetKeyDown(CustomInputManagerScript.keyBind["Slot5"]))
            {
                if (isAltPressed)
                {
                    playerInventory.SwapInventorySlot(currentIndex, 4);
                }

                else
                {
                    index = 4;
                }
            }

            if (currentIndex != index)
            {
                playerInventory.SwitchActiveIndex(index);
                currentIndex = index;
            }

            if (Input.GetKeyDown(CustomInputManagerScript.keyBind["Loot"]))
            {
                playerInventory.Collect();
            }

            if (Input.GetKeyDown(CustomInputManagerScript.keyBind["Drop"]))
            {
                //on drop l'objet un peu plus haut que la position y du joueur sinon, l'objet rentre dans le sol et n'est plus ramassable
                var newPosition = transform.position + new Vector3(0f, 0.1f, 0f);
                playerInventory.Drop(newPosition, playerInventory.currentSlotIndex);
            }
        }