- Home /
AudioClip management by script with Unity 5
Before, with Unity 4.6, I was using the following script, to manage the activation of AudioClip sound effects:
var positiveSound : AudioClip;
var negativeSound : AudioClip;
function OnGUI ()
{
if(GUILayout.Button(PositiveTexture))
{
audio.clip = positiveSound;
audio.Play();
}
if(GUILayout.Button(NegativeTexture))
{
audio.clip = negativeSound;
audio.Play();
}
}
Now, Unity is telling me that this kind of code is obsolet and I need to replace it with GetComponent(AudioSource); , so I replaced the first part audio.clip = positiveSound; with GetComponent("positiveSound"); to find the necessary AudioClip, but once I've found it, how do I play it? I tried many combinations, but no one worked. I tried to search the site for an answer to my problem, but I keep finding only pre-Unity 5 tutorials and instructions.
Your answer
Follow this Question
Related Questions
Why some audio files are not working in Unity? 0 Answers
Keyword 'void' cannot be used in this context 1 Answer
Unity [Command] function UNetWeaver error 1 Answer
I cant start a Script with MonoDevelop. 0 Answers
How to follow a target (prefab) with the visual scripting: Behavior machine Pro? 0 Answers