Mouse Look Script Reset?

I’m working on a situation in which as you’re flying around, the user can press a space bar to pull up some GUITextures. When they press the spacebar, it disables the default Mouse Look Script that is attached to the parent of the camera so they can move the mouse and select one of the buttons.

Once these GUITextures are visible, they can click on one which then moves and orients the camera to a new location and rotation.

The problem is that when the user releases the spacebar, it reenables the Mouse Look Script, and that jerks the camera (or more accurately the parent of the camera), back to the rotation values it had before the Mouse Look Script was turned off.

Is there a way to reset or flush the rotation values that seem to be being stored when the Mouse Look Script is turned off, so that when it’s turned back on, it can use it’s newly inherited values?

Thanks.

Should I maybe destroy the object and then reinstantiate it?

Anyone? Please…am I unclear with the question?

Well, I figured it out. Thought I’d post the solution.

The trick was to make sure in the first script to Destroy the MouseLook script on the camera:

Destroy(go.GetComponent("MouseLook"));

Then at the end of the second script, after aligning the camera to the new location, readd the MouseLook script:

Maincamparent.AddComponent ("MouseLook");

There’s a little pop, but it does the trick.

Thanks for sharing, could be useful 8)

Hi wadamw

I am in the process of building something like what you are trying to do. A presentation where you can activate GUI and when you do you disable the MouseLook script. I am totally new in the world of scripting and I am wondering if it is possible to see some of the script you are writing for the disable and enable of the MouseLook. I see the part you have posted but I am not able to make use of it as I can’t see the connection between the script parts an the function as a whole.

Thank you!

BR

Sure thing. I’d be glad to. I don’t have the scripts with me (I’ll post tomorrow); if I don’t, please post again so it sends me a reminder.

Thank you!! looking forward to it! :smile:

BR

Hi Harald,

Sorry to be so slow posting this. Got the client breathing down my neck and some things are just slipping on my list.

Anyway, here’s how I’m accomplishing it:

// All the necessary var's are up here

if (Input.GetKeyDown("space")){
	if (showGUI)
		guienabled(false);
	else
		guienabled(true);
	
}
}

function guienabled(direction:boolean){
	if(direction){
		GUI.enabled=true;
		Screen.lockCursor = false;

//You could probably leave this out in most cases.  It was necessary for me because of some specialty Thruster script I was using.

Destroy(Maincamparent.GetComponent("MouseLook"));
		Maincamparent.GetComponent("Thruster").enabled = false;

		Screen.showCursor= true; 
		showGUI=true;
	}
	else {
		Screen.lockCursor = true;
		Screen.showCursor= false;

			if (!Maincamparent.GetComponent("MouseLook")){
		/*	Maincamparent.transform.rotation = Quaternion.identity;*/
			Maincamparent.AddComponent ("MouseLook");
		}	
		showGUI=false;
		GUI.enabled=false;
		Maincamparent.GetComponent("Thruster").enabled = true;
		}
}

function OnGUI () {
	GUI.skin = mySkin;
	if (showGUI){

//Then all of your GUI stuff down here...

Does that make sense?

Hi

Thank you! I am really gratefull for your help!!
I will check it out!!

BR

I know this is an old question. But i spent days looking for an answer. Here is how i did it.