- Home /
Audio Problem
I am trying to play a audio when an object is destroyed the only problem with that is when I click "Play on Active" It just keeps playing every time the object is spawned. One way I was able to fix this was through turning off "Is Trigger". But when I do that the object just floats away. I do have tumble on it. I do not know if the code or something for it is messed up but here are all the scripts I have attached to it.
Random Rotator
using UnityEngine;
using System.Collections;
public class RandomRotator : MonoBehaviour
{
public float tumble;
void Start ()
{
rigidbody.angularVelocity = Random.insideUnitSphere * tumble;
}
}
Destroy By Contact
using UnityEngine;
using System.Collections;
public class DestroyByContact : MonoBehaviour
{
public GameObject explosion;
public GameObject playerExplosion;
void OnTriggerEnter(Collider other) {
if (other.tag == "Boundary") {
return;
}
Destroy (other.gameObject);
Destroy (gameObject);
Instantiate (explosion, transform.position, transform.rotation);
if (other.tag == "Player") {
Instantiate (playerExplosion, other.transform.position, other.transform.rotation);
}
}
}
Mover
using UnityEngine;
using System.Collections;
public class Mover : MonoBehaviour
{
public float speed;
void Start ()
{
rigidbody.velocity = transform.forward * speed;
}
}
Going to need a little more info.
Firstly, it keeps playing when what object is spawned?
When you say keep playing, do you mean like looped?
Does the explosion object have the loop flagged on the audio source and does the explosion destroy itself when it is done?
Every time a asteroid is spawned it makes the sound like it is being destroyed but it doesn't actually get destroyed.
No not a loop, just a sound every time it is spawned.
It is not flagged.
Your answer
![](https://koobas.hobune.stream/wayback/20220613133035im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why my sound it's not attaching to my Flashlight 2 Answers
one shot Sound on collision. Unity 4.0 problem. 2 Answers
Audio Script doesn't work 0 Answers
Global Varible Problem 2 Answers
Using High Pass Filter with script 2 Answers