the sound is repeated at specified “loop = false;”. Why? and how can I play a sound in only 1 second?
Code
using UnityEngine;
using System.Collections;
public class sound : MonoBehaviour {
public AudioClip impact;
AudioSource audio;
// Use this for initialization
void Start () {
audio = GetComponent<AudioSource> ();
}
void OnCollisionEnter2D(Collision2D col){
audio.loop = false;
audio.PlayOneShot (impact, 1f);
}
// Update is called once per frame
void Update () {
}
}
Sorry, it’s my fail. I did not write the name of the object hit, in contact with which the sound should be played. How can I play a sound in only 1 second? I can not use “yield return” because in one second can be 3 a collision and stop the sound at all Sorry for my English:) I hope you understand me.