I try to build an audioplayer. It will appear if the player has triggered it by hitting a collider.In the moment the autonaming of the buttons works (although the apostroph gets replaced with an underscore).
But the main thing(playing the actual audio) is unfortunatly not working.
Also i need a way of stepping tracks. Thought of increasing or decreasing the index of the tracks array, but i need a little help here.
Later i want to have a pic for each track(but first i have to get the audiopart working).
I´m thankful for any hint or advice.
This is the code so far:
// The AudioPlayerScript
var gSkin : GUISkin;
//private var showAudioPlayer = false;
var showAudioPlayer = false ;
// The actual AudioPlayer Window -> 400x300
var audioPlayerRect = Rect (Screen.width/2-200, Screen.height/2-170, 400,300);
//For Scrollview -The variable to control where the scrollview 'looks' into its child elements.
var scrollPosition : Vector2;
//an image for the track
var clipPic : Texture2D;
// AudioLibrary
var tracks : AudioClip[];
function OnGUI() {
if (gSkin)
GUI.skin = gSkin;
else
Debug.Log("AudioPlayerGUI: GUI Skin object missing!");
if(showAudioPlayer)
audioPlayerRect = GUILayout.Window (0, audioPlayerRect, AudioPlayerWindow, "AudioPlayer");
}//OnGUI
// Make the contents of the AudioPlayerWindow
function AudioPlayerWindow (windowID : int) {
//AudioPlayer Group
GUILayout.BeginVertical();
//a centered Pic for the track
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label(clipPic, GUILayout.MaxWidth(100), GUILayout.MaxHeight(100));//the pic
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
// Begin a scroll view. All rects are calculated automatically
scrollPosition = GUILayout.BeginScrollView (scrollPosition, GUILayout.Width (100), GUILayout.Height (100));
//create buttons for all audioclips
for (var track: AudioClip in tracks){
audio.clip = track;
trackName = audio.clip.name;
//NOT WORKING YET!!!!!!!! Play the track of the button
if (GUILayout.Button(trackName,GUILayout.MaxWidth(350))){
audio.clip = track;
print(trackName);
audio.Play();
audio.loop= false;
}//if
}//for
// End the scrollview we began above.
GUILayout.EndScrollView ();
GUILayout.Space(10);
GUILayout.BeginHorizontal ();
GUILayout.FlexibleSpace();
if (GUILayout.Button ("","prevButton", GUILayout.MaxWidth (30),GUILayout.MaxHeight (30))) {
//step back in tracks array ??
}//if
GUILayout.Space(10);
if (GUILayout.Button ("","stopButton", GUILayout.MaxWidth (30),GUILayout.MaxHeight (30))) {
audio.Stop();
}//if
if (GUILayout.Button ("","pauseButton", GUILayout.MaxWidth (30),GUILayout.MaxHeight (30))) {
audio.Pause();
}//if
if (GUILayout.Button ("","playButton", GUILayout.MaxWidth (30),GUILayout.MaxHeight (30))) {
audio.Play();
}//if
GUILayout.Space(10);
if (GUILayout.Button ("","nextButton", GUILayout.MaxWidth (30),GUILayout.MaxHeight (30))) {
//step forward in tracks array ??
}//if
GUILayout.FlexibleSpace();
GUILayout.FlexibleSpace();
// close Window
if (GUILayout.Button ("Close", GUILayout.MaxWidth (70)))
showAudioPlayer = false;
GUILayout.EndHorizontal ();
GUILayout.EndVertical();
}//AudioPlayerWindow
function OnTriggerEnter () {
showAudioPlayer = true;
}
function OnTriggerExit () {
showAudioPlayer = false;
}
@script ExecuteInEditMode
@script RequireComponent(AudioSource)