private void ShootRPC(int shooterId) { var weapon = weaponHolder.currentWeapon; var consommable = consommableHolder.currentConsommable; if (weapon != null) { weapon.Fire(playerCameraTransform, playerID); if (weapon.currentAmmo > 0) { //play the weapon sound AudioManagerScript.Play3D(audioSource, weapon.weaponSound); } //the item can have changed since the player shoot. Update UI only if necessary var update = weapon == weaponHolder.currentWeapon; if (playerID == shooterId && update) { uiScript.SetAmmoCounter(weapon.currentAmmo); } } else if (consommable != null) { if (playerID == shooterId) { playerInventory.UseItem(playerInventory.currentSlotIndex); StartCoroutine(ApplyBonusOverTime(consommable.GetTime(), consommable.GetHealth(), consommable.GetShield())); } } }
// Sets the instance reference, if not set already, // and keeps listening to scene changes. private void Awake() { if (instance != null) { return; } instance = this; DontDestroyOnLoad(gameObject); SceneManager.sceneLoaded += OnSceneLoaded; }
/// <summary> /// Start a new match. /// </summary> public void Play() { //play the waiting music AudioManagerScript.PlayMusic(0); if (PhotonNetwork.inRoom) { // Close the room so that a new player can not join the game PhotonNetwork.room.IsOpen = false; PhotonNetwork.room.IsVisible = false; PhotonNetwork.LeaveRoom(); } // We try to join a random room PhotonNetwork.JoinRandomRoom(); }
/// <summary> /// Cancel matchmaking and return to lobby /// </summary> public void Cancel() { //stop the waiting music AudioManagerScript.GetInstance().musicSource.Stop(); StopAllCoroutines(); // Close the room so that a new player can not join the game PhotonNetwork.room.IsOpen = false; PhotonNetwork.room.IsVisible = false; // We leave the room PhotonNetwork.LeaveRoom(); // We show the main menu mainMenuScript.ShowMainMenu(); }
private void Simulate(float dt) { if (roboLogic.isInPause) { return; } // Limit the diagonal speed float inputModifyFactor = Math.Abs(input.inputX) > 0.0001f && Math.Abs(input.inputY) > 0.0001f ? .7071f : 1.0f; // Handle the movement if (grounded) { // Set double jump to true on grounded doubleJump = true; // Disable the jump layer when the player is on the ground roboLogic.animator.SetLayerWeight(1, 0); // Disable the thrusters when the player is not flying roboLogic.thrusters.SetActive(false); moveDirection = new Vector3(input.inputX * inputModifyFactor * speed, 0f, input.inputY * inputModifyFactor * speed); //Stop the jetpack sound if we are grounded if (roboLogic.audioSource.isPlaying && roboLogic.audioSource.clip == roboLogic.audioClips[1]) { roboLogic.audioSource.Stop(); } //Play the run audio if (roboLogic.isMoovingAudio && !roboLogic.audioSource.isPlaying) { AudioManagerScript.Play3D(roboLogic.audioSource, roboLogic.audioClips[0]); } // Animate the player for the ground animation roboLogic.animator.SetFloat("VelX", moveDirection.x * speed); roboLogic.animator.SetFloat("VelY", moveDirection.z * speed); moveDirection = transform.TransformDirection(moveDirection); } else { moveDirection.x = input.inputX * speed * inputModifyFactor; moveDirection.z = input.inputY * speed * inputModifyFactor; // Animate the player for the fly animation roboLogic.animator.SetFloat("VelX", 0f); roboLogic.animator.SetFloat("VelY", 0f); //only play the fly animation on the remote if (!photonView.isMine) { // Enable the thrusters when the player is flying roboLogic.thrusters.SetActive(true); } moveDirection = transform.TransformDirection(moveDirection); } //Play audio only when we are going up roboLogic.isJumpingAudio = moveDirection.y > 0; if (roboLogic.isJumpingAudio) { //Stop the running sound if we are not grounded if (roboLogic.audioSource.isPlaying && roboLogic.audioSource.clip == roboLogic.audioClips[0]) { roboLogic.audioSource.Stop(); } //Play the jetpack sound if (!roboLogic.audioSource.isPlaying) { AudioManagerScript.Play3D(roboLogic.audioSource, roboLogic.audioClips[1], 1.15f); } } else { //Stop the jumping sound when we are falling if (roboLogic.audioSource.isPlaying && roboLogic.audioSource.clip == roboLogic.audioClips[1]) { roboLogic.audioSource.Stop(); } } if (input.jump) { // We override the base layer when the player is jumping roboLogic.animator.SetLayerWeight(1, 1); if (grounded) { moveDirection.y = flyForce; } else { if (doubleJump) { doubleJump = false; moveDirection.y = flyForce; } } } // Rotate the player on the Y axis transform.rotation *= Quaternion.Euler(0, input.mouse.x * aimSensitivity, 0); // Apply gravity moveDirection.y -= gravity * dt; //Set the mooving bool roboLogic.isMoovingAudio = Math.Abs(moveDirection.x) > 0.0001f || Math.Abs(moveDirection.z) > 0.0001f; // Move the controller, and set grounded true or false depending on whether we're standing on something grounded = (controller.Move(moveDirection * dt) & CollisionFlags.Below) != 0; }