Ejemplo n.º 1
0
 void HandlePlayerLevelUp(int newLevel)
 {
     Debug.Log(string.Format("Player is now level: {0}", newLevel));
     stats.PersistentPlayerData.PerkPoints++;
     // Play level up sound
     GetComponent <AudioSource>().PlayOneShot(AudioDatabase.GetClip("Pickup"));
 }
Ejemplo n.º 2
0
    void UpdateWalkSound()
    {
        if ((currentWalkSoundDelay += Time.deltaTime) >= walkSoundRate)
        {
            currentWalkSoundDelay = 0f;
            feetAudioSource.PlayOneShot(AudioDatabase.GetClip(walkAudioClipsId[currentWalkAudioIndex]));

            if (currentWalkAudioIndex < walkAudioClipsId.Length - 1)
            {
                currentWalkAudioIndex++;
            }
            else
            {
                currentWalkAudioIndex = 0;
            }
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Plays an audio clip in the music audio source.
    /// </summary>
    /// <param name="clipIndex">The index of the clip to play</param>
    /// <param name="addState">DontReplace: If a clip is already playing, don't do anything.<br></br>Replace: Always play the clip.<br></br>Queue: If a clip is already playing, play it once the clip has stopped playing.</param>
    /// <param name="maxVolume">The maximum volume the clip will ever reach</param>
    /// <param name="loop">Whether the clip should be looped</param>
    /// <param name="fadeInSpeed">Speed at which to fade-in. 1 = instantaneous</param>
    /// <param name="fadeOutSpeed">Speed at which to fade-out the previous clip (if AddState.Queue). 1 = instantaneous</param>
    public void PlayClip(string audioClipId, AddState addState, float maxVolume = 1f, bool loop = false, float fadeInSpeed = 1f, float fadeOutSpeed = 1f)
    {
        if (!musicAudioSource.isPlaying || addState == AddState.Replace)
        {
            musicAudioSource.clip = AudioDatabase.GetClip(audioClipId);
            StartFadeIn(fadeInSpeed, maxVolume);
            musicAudioSource.loop = loop;
        }
        else if (addState == AddState.Queue)
        {
            if (currentQueueWait != null)
            {
                StopCoroutine(currentQueueWait);
            }

            StartFadeOut(fadeOutSpeed);
            currentQueueWait = StartCoroutine(WaitForStop(audioClipId, maxVolume, loop, fadeInSpeed));
        }
    }
Ejemplo n.º 4
0
    void ControlManager()
    {
        mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        if (Input.GetAxis("Fire1") == 1)
        {
            //print("Ping");
            if (currentWeapon)
            {
                // Attempt to fire the weapon, if the weapon does fire, increase bullets shot.
                if (currentWeapon.PrimaryFire())
                {
                    stats.BulletsShot++;
                }

                OnWeaponChanged?.Invoke(currentWeapon);
            }
        }

        if (Input.GetAxis("Fire2") == 1)
        {
            if (currentWeapon)
            {
                currentWeapon.SecondaryFire();
                OnWeaponChanged?.Invoke(currentWeapon);
            }
        }

        if (Input.GetButtonDown("Reload"))
        {
            if (currentWeapon)
            {
                currentWeapon.ReloadAll();
                OnWeaponChanged?.Invoke(currentWeapon);
            }
        }

        if (Input.GetButtonDown("Ability1"))
        {
            try
            {
                if (!AbilityController)
                {
                    return;
                }

                AbilityController.UseAbility(0);
            }
            catch (Exception e)
            {
                Debug.LogWarning("Ability 1 not found");
            }
        }

        if (Input.GetButtonDown("Ability2"))
        {
            try
            {
                AbilityController.UseAbility(1);
            }
            catch (Exception e)
            {
                Debug.LogWarning("Ability 2 not found");
            }
        }
        if (Input.GetButton("CharJump"))
        {
            if (jumpController.Jump(out var newEnemy))
            {
                controlledObject = newEnemy;
                GetComponent <AudioSource>().PlayOneShot(AudioDatabase.GetClip("Body Swap"));
                HandleNewControlledObject();
            }
        }
    }
 public void Init(string audioClipId, float lifeTime, float volume)
 {
     GetComponent <AudioSource>().PlayOneShot(AudioDatabase.GetClip(audioClipId), volume);
     StartCoroutine(Destroy(lifeTime));
 }