Can't Drag Window

This code puts my media player into a GUI Window. It works, except I can’t click and drag the window.

var attachedAudio : AudioClip;
var looping = false;
var timeSinceStart = 0.0;
var refreshTime = 0;
var windowRect = Rect (20, 20, 400, 300);

function Start () {
	CountSeconds ();
}

function OnGUI () {
	windowRect = GUILayout.Window (0, windowRect, PlayerWindow, "Wanilla Media Player");
}

function PlayerWindow (windowID : int) {
	
	GUILayout.Label(timeSinceStart + " / " + attachedAudio.length + " seconds");
	
	GUILayout.BeginHorizontal();
	
	if (GUILayout.Button("Play")) {
		audio.clip = attachedAudio;
		audio.Play();
		refreshTime = 1;
	}
	if (GUILayout.Button("Pause")) {
		audio.clip = attachedAudio;
		audio.Pause();
		refreshTime = 0;
	}
	if (GUILayout.Button("Stop")) {
		audio.clip = attachedAudio;
		audio.Stop();
		refreshTime = 0;
		timeSinceStart = 0.0;
	}
	
	GUILayout.EndHorizontal();
	
	timeSinceStart = GUILayout.HorizontalSlider (timeSinceStart, 0.0, attachedAudio.length);
	
	
	GUILayout.BeginHorizontal();
	
	looping = GUILayout.Toggle (looping, "Loop");
	
	if (looping == true) {
		audio.loop = true;
	} else {
		audio.loop = false;
	}
	
	GUILayout.Label ("Pitch: " + audio.pitch);
	
	if (GUILayout.Button ("Reset Pitch")) {
		audio.pitch = 1.0;
	}
	
	GUILayout.EndHorizontal();
	audio.pitch = GUILayout.HorizontalSlider (audio.pitch, 0.5, 2.0);
}

function CountSeconds () {
	while (timeSinceStart < attachedAudio.length) {
		timeSinceStart ++;
		yield WaitForSeconds (refreshTime);
	}
}

Maybe because you’re not using DragWindow? :wink:

–Eric

:eyes: Whaaat? Well, after looking it up, that worked, but still. All of the documentation for GUILayout.Window says that it is draggable, and none of the examples have GUI.DragWindow in them. How was I supposed to figure it out?

'Cause the docs say so? :slight_smile: “Windows float above normal GUI controls, feature click-to-focus and can optionally be dragged around by the end user.”

Might want to look here again. :wink:

–Eric

Is the playing length of the audio file going to stay the same with a lot of wild pitch bending? It would be cool if so.

Eric - I was looking at the GUILayout.Window page, not the GUI.Window page. Theres nothing about drag on there except “Can be optionally dragged by the end user”

Jessy - I’m still working on getting the playback head to work, but from what I’ve seen, the song gets shorter as you bend the pitch up. Unless Unity has Pitch Bending that doesn’t increase speed as well?

Either way has its benefits and drawbacks. I think an algorithm that kept length the same would be the most useful, but that also introduces more artifacts.