public void PlayAudio(Modifier powerupType) { if (isPlayingSound) { // Stop playing the sound // Note, if there are any other FX playing, this will stop it Debug.Log("Stopping existing powerup music"); aSource.PlayFx(AudioManagement.SoundType.STOP); isPlayingSound = false; } // Play the appropriate sound based on what powerup is given if (powerupType == Modifier.INVINCIBLE) { aSource.PlayFx(AudioManagement.SoundType.INVINCIBILITY); } else if (powerupType == Modifier.JUMPHEIGHT) { aSource.PlayFx(AudioManagement.SoundType.POWERUP); } else if (powerupType == Modifier.SPEED) { aSource.PlayFx(AudioManagement.SoundType.POWERUP); } else { Debug.Log("Powerup type has no sound!"); return; } isPlayingSound = true; }
void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag != floorGameObjectTag) { if (collision.gameObject.tag == "MainPlayer") { GameObject playerGameObject = GameObject.FindWithTag("MainPlayer"); Player player = null; if (playerGameObject != null) { player = playerGameObject.GetComponent <Player> (); } const float THRESHOLD_DISTANCE = 0.05f; const int HEIGHT = 2; if (Mathf.Abs(playerGameObject.transform.position.y) <= (Mathf.Abs(transform.position.y) - HEIGHT + THRESHOLD_DISTANCE)) { // player jumped on enemy head, kill the enemy UpdateHealth(0); Destroy(gameObject); } else { // player touched enemy, hurt the player by 25% of their max health player.ApplyDamage(MAX_HEALTH / 4); if (soundManager == null) { soundManager.PlayFx(AudioManagement.SoundType.DAMAGE); } } } velocity *= -1; } }
public void Jump() { // Apply 7 units of force in the y direction. rb2d.AddForce(new Vector2(0, 7), ForceMode2D.Impulse); aSource.PlayFx(AudioManagement.SoundType.JUMP); }