I’m at the stage where I start adding sound and when I add the sound it just adds the audio clips to the hierarchy instead of the game object I’ve assigned it to. I think I’ve gotten that figured out but now that the music is playing the explosion visual effects for my player game object and my asteroid game object stopped working.
Here is my code for my Destroy By Contact script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyByContact : MonoBehaviour
{
public GameObject explosion;
public GameObject playerExplosion;
maby the prefab “playerExplosion” does not have an audio source that plays automatically, or the clip slot is empty.
its best to address audio components directly…having different explosions sounds is nice too
public AudioSource PlayerVoice; // sets where audio comes from
public AudioClip[] Chatter;// sets the audio clip Array the Audio Source Plays.
public float CommVolume = .45f; // sets the audio volume - you'll need this later = user volume level
//somewhere when you want to play audio clip
if ((PlayerVoice.isActiveAndEnabled) && (Chatter.Length > 0)) //is the audio source active and do I have a clip to play?
PlayerVoice.clip = Chatter[Random.Range(0, Chatter.Length)]; // now set a random clip from that clip array
if (!PlayerVoice.isPlaying) // is the audio source already playing a clip? - no then
PlayerVoice.Play(); // play the audio clip assigned above
or just call a new method
if (other.tag == "Player")
iExplode(true);
else
iExplode(false);
private void iExplode(bool isPlayer){
if (isPlayer)
Instantiate (playerExplosion, other.transform.position, other.transform.rotation);
else
Instantiate(explosion, transform.position, transform.rotation);
if (Chatter.Length > 0) //is the audio source active and do I have a clip to play?
PlayerVoice.clip = Chatter[Random.Range(0, Chatter.Length)]; // now set a random clip from that clip array
PlayerVoice.Play(); // play the audio clip assigned above
}