- Home /
SCRIPT FOR UNITY 5 (TRIGGER SOUND)
I dont see any script for unity 5 about trigger sound, I only found scripts for unity 4 and this dont work. So I need your help. (Sorry for my bad english I am from spain). EDIT:
var Sound : AudioClip;
function OnTriggerEnter(){ audio.PlayOneShot(Sound);
}
This is the script that I use, AND I HAVE GOT THIS ERROR:
Assets/DI�LOGOS/SONIDOPERSONAJES.js(4,2): BCE0144: 'UnityEngine.Component.audio' is obsolete. Property audio has been deprecated. Use GetComponent() instead. (UnityUpgradable)
I want also that this sound will be delete when the sound finish. Thaks.
I think your question might need some more details. "this don't work" isn't exactly enough for people to know what your problem is.
i think your doing unity 4's way of playing sound. try adding an audiosource to your script (im not a javascript coder so your going to have to look up how to do that). then in your OnTriggerEnter function do AudioSource.PlayClipAtPoint(Sound, transform.position);
Answer by tanoshimi · Jun 22, 2015 at 04:48 PM
The error tells you the answer...
audio.PlayOneShot(Sound);
should be
GetComponent.<Audio>().PlayOneShot(Sound);
Answer by Anish Kumar Kodeboyina · Jun 22, 2015 at 04:58 PM
AudioSource.PlayClipAtPoint(Audioclip, transform.position);