Hello, I'm not really good in GUI scripting but I'm trying to create this avatar selection grid with sound and texture. I had an earlier version of the script where I got the textures to work but it is the sounds that I have difficulties with.
I suppose there is something I'am missing out on. I'm not really sure how the Selection grid works yet and currently I'am really tired and not focusing straight and not sure what to do so, yeah, asking you guys.
This is the script I have so far, and neither the sounds or textures are appearing or playing.
TL;DR Need help to get sound effects when pressing buttons on the grid.
I appriciate all answers, thanks in advance ^^
#pragma strict
var native_width : float = 1920;
var native_height : float = 1080;
var Avatar0 : Texture2D;
var Avatar1 : Texture2D;
var Avatar2 : Texture2D;
var Avatar3 : Texture2D;
var Value0 = 0;
var Value1 = 1;
var Value2 = 2;
var Value3 = 3;
var storeIndex =0;
var Sound0 : AudioClip;
var Sound1 : AudioClip;
var Sound2 : AudioClip;
var Sound3 : AudioClip;
var myStyle : GUIStyle;
var selGridInt : int = 0;
var selStrings : String[] = ["Char1", "Char2", "Char3", "Char4"];
function OnGUI () {
var rx : float = Screen.width / native_width;
var ry : float = Screen.height / native_height;
GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (rx, ry, 1));
GUI.Box (Rect (1700,20,200,200), "");
selGridInt = GUI.SelectionGrid (Rect (1480, 20, 200, 100), selGridInt, selStrings,2);
if (storeIndex != selGridInt){
storeIndex = selGridInt;
if(storeIndex == Value0)
{
GUI.Box (Rect (1700,20,200,200), GUIContent("", Avatar0));
audio.clip = Sound0;
audio.Play();
}
}
if (storeIndex != selGridInt){
storeIndex = selGridInt;
if(storeIndex == Value1)
{
GUI.Box (Rect (1700,20,200,200), GUIContent("", Avatar1));
audio.clip = Sound1;
audio.Play();
}
}
if (storeIndex != selGridInt){
storeIndex = selGridInt;
if(storeIndex == Value2)
{
GUI.Box (Rect (1700,20,200,200), GUIContent("", Avatar2));
audio.clip = Sound2;
audio.Play();
}
}
if (storeIndex != selGridInt){
storeIndex = selGridInt;
if(storeIndex == Value3)
{
GUI.Box (Rect (1700,20,200,200), GUIContent("", Avatar3));
audio.clip = Sound3;
audio.Play();
}
}
}
↧