I am using this audio clip from Shell Falling Sounds | Effects | Sound Bites | Sound Clips from SoundBible.com
The audio clip plays twice in my game. Ideally it should play exactly it plays in the .mp3 file. What I want is that it should play only once when it hits the floor(onCollisionEnter)
here’s the script attached to bullet shell
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(ConstantForce))]
[RequireComponent(typeof(AudioSource))]
public class bulletShell : MonoBehaviour {
public Vector3 turnForce;
private ConstantForce forceComponent;
private AudioSource shellClip;
/// Awake is called when the script instance is being loaded.
void Awake() {
forceComponent = GetComponent<ConstantForce>();
shellClip = GetComponent<AudioSource>();
turnForce.x = Random.Range(-180, 180);
turnForce.y = Random.Range(-180, 180);
// turnForce.z = Random.Range(-200, 200);
forceComponent.torque = turnForce;
}
void OnCollisionEnter(Collision col) {
Debug.Log("I touched the ground");
shellClip.Play();
Destroy(gameObject, 3f);
forceComponent.enabled = false;
}
}