- Home /
Question by
Eizdieler · Oct 25, 2012 at 10:31 AM ·
audiosourcerequirecomponent
Does not work: @script RequireComponent(AudioSource)
Hi,
I´m going through the Unity Game Dev Essentials and have a little problem with the
@script RequireComponent(AudioSource)
command. It simply doesn´t work.
It should add an audio source component to the object I add this script to, but it doesnt´t.
In chapter 8 there is this simple script:
var levelToLoad : String;
var normalTexture : Texture2D;
var rollOverTexture : Texture2D;
var beep : AudioClip;
function OnMouseEnter(){
guiTexture.texture = rollOverTexture;
}
function OnMouseExit(){
guiTexture.texture = normalTexture;
}
function OnMouseUp(){
audio.PlayOneShot(beep);
yield new WaitForSeconds(0.35);
Application.LoadLevel(levelToLoad);
}
@script RequireComponent(AudioSource)
Anyone knows what could cause it not to appear in the Inspector ? :(
Thanks in advance for any help !
Comment
Remove the script from your object, and add again. It should add the new required component once you add it.
What you are experiencing may be due to the fact that you have added this piece of code after your script was already attached to an object.