Im trying to add sound effect to my game i made a soundmanager and gave it 3 audio sources then i made this script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SoundManager : MonoBehaviour
{
// public
public AudioSource DeathSound;
public AudioSource ScoreSound;
public AudioSource Powerup;
// void
public void DeathS()
{
DeathSound.Play();
}
public void ScoreSoundS()
{
ScoreSound.Play();
}
public void PowerupS()
{
Powerup.Play();
}
}
How would i implement it into my p[layer script so that when he dies it will play this i my playerscript
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
// public
public TimeManager timeManager;
public float force = 5f;
public Rigidbody2D rb;
public bool isGrounded;
// private
GameObject playerPrefab;
private Vector2 startSwipe;
private Vector2 endSwipe;
// void
void Start()
{
playerPrefab = GameObject.FindGameObjectWithTag("Player");
}
void Update()
{
// movement
if (Input.GetMouseButtonDown(0))
{
startSwipe = Camera.main.ScreenToViewportPoint(Input.mousePosition);
}
if (Input.GetMouseButtonUp(0))
{
endSwipe = Camera.main.ScreenToViewportPoint(Input.mousePosition);
Swipe();
}
// Slo-mo, Squeeze & health
if (Input.GetMouseButtonDown(0) && isGrounded == false)
{
timeManager.DoSlowMotion();
Squeeze();
GetComponent<PlayerHealth>().numOfHearts --;
}else if (Input.GetMouseButtonUp(0) && isGrounded == false)
{
UnSqueeze();
}
}
void Swipe()
{
Vector2 swipe = endSwipe - startSwipe;
rb.AddForce(swipe * force, ForceMode2D.Impulse);
}
void Squeeze()
{
playerPrefab.transform.localScale = new Vector3(0.45f, 0.5f, 1f);
}
public void UnSqueeze()
{
playerPrefab.transform.localScale = new Vector3(0.5f, 0.5f, 1f);
}
}