Hello, everyone. I'm doing a project for school on the connection of music to the brian, and I'm using Unity because of it's gui system. I need to be able to fast forward and rewind audio clips, and I'm doing so with audio.pitch. However, the fast forward button has no effect, but the rewind button works fine. All help would be appreciated!!! :)
Here is my code:
@script RequireComponent(AudioSource)
private var INFOscrollVector : Vector2 = Vector2.zero;
private var AUDIOscrollVector : Vector2 = Vector2.zero;
var info : String;
var songs : AudioClip[];
var clipButtonSize : float;
var PlayIcon : Texture2D;
var PauseIcon : Texture2D;
var ffIcon : Texture2D;
var rwIcon : Texture2D;
var showAudioInterface : boolean = true;
private var aClip : AudioClip;
private var p : float;
function Awake()
{
p = audio.pitch;
}
function OnGUI()
{
AudioInterface();
}
function Update()
{
audio.clip = aClip;
}
function AudioInterface()
{
//Background Boxes
GUI.Box(Rect(10, 10, Screen.width/2-5, Screen.height - 60), "");
GUI.Box(Rect(Screen.width/2+5, 10, Screen.width/2-10, Screen.height - 60), "");
GUI.Box(Rect(10, Screen.height-50, Screen.width - 15, 40), "");
//The Play/Pause and other options
GUI.BeginGroup(Rect(10, Screen.height-50, Screen.width - 15, 40));
if(GUI.Button(Rect(0, 0, 40, 40), PlayIcon))
{
audio.Play();
}
if(GUI.Button(Rect(40, 0, 40, 40), PauseIcon))
{
audio.Pause();
}
if(GUI.RepeatButton(Rect(80, 0, 40, 40), ffIcon))
{
audio.pitch = p * 2;
} else
{
audio.pitch = p;
}
if(GUI.RepeatButton(Rect(120, 0, 40, 40), rwIcon))
{
audio.pitch = p/2;
} else
{
audio.pitch = p;
}
GUI.EndGroup();
//The Info Scroll View
INFOscrollVector = GUI.BeginScrollView(Rect(10, 10, Screen.width/2-5, Screen.height - 60), INFOscrollVector, Rect(10, 10, Screen.width/2-25, 10000));
GUI.Label(Rect(10, 10, Screen.width - 20, 10000), info);
GUI.EndScrollView();
//The Audio Scroll View
AUDIOscrollVector = GUI.BeginScrollView(Rect(Screen.width/2+5, 10, Screen.width/2-10, Screen.height - 60), AUDIOscrollVector, Rect(10, 10, Screen.width/2-30, clipButtonSize*songs.length));
for(i = 0; i < songs.length; i++)
{
if(GUI.Button(Rect(10, 10+(i*clipButtonSize), Screen.width/2-30, clipButtonSize), songs[i].name))
{
aClip = songs[i];
}
}
GUI.EndScrollView();
}
asked
Apr 28 '11 at 08:10 PM
zmar0519
946
●
59
●
66
●
78