I wrote a static function to display a dialog box in my game with the character name, message, the works. I can even play an audio blip to represent the character’s voice. But when I run this code:
static function dialogBox (boxSize : String, message : String, charaName : String, buttonName : String, messageNumb : int, Skin : GUISkin, charaSound : AudioClip) {
GUI.skin = Skin;
var boxX;
var boxY;
if (boxSize == "Small") {
boxX = 240;
boxY = 150;
}
if (boxSize == "Large") {
boxX = 260;
boxY = 200;
}
GUI.Box (Rect ((Screen.width / 2) - (boxX / 2), (Screen.height / 2) - (boxY / 2), boxX, boxY), charaName);
GUI.Label (Rect ((Screen.width / 2) - ((boxX / 2) - 10), (Screen.height / 2) - ((boxY / 2) - 15), boxX - 20, boxY - 50), message);
if (GUI.Button (Rect ((Screen.width / 2) - ((boxX / 2) - 10), (Screen.height / 2) + ((boxY / 2) - 25), boxX - 20, 20), buttonName)) {
audio.PlayOneShot(charaSound);
return messageNumb + 1;
}
}
I get this error:
An instance of type ‘UnityEngine.Component’ is required to access non static member ‘audio’.
Suggestions?