x


toggleing the mouse visibility

(note: I barely get by with scripting and dont know what alot of things mean, so you may have to go into more detail if i ask) I was wondering if i could use a button to toggle the visibility of the mouse. I am using the First Person Controller Prefab, and i've added in the mouse look script Screen.showCursor = false; right after the void update and the mouse is gone. now i just recently realized that the mouse look script is not in java. i was wondering is there anyway i can use a different java sheet to say something like (and this is not a working java script at all, its just a very VERY rough example)

var Toggleme:boolean;
if(Input.GetButtonDown("button here"))
{
if(Toggleme = true}
{
Toggleme = false;
}
else
{
Toggleme = true;
}
}

and then say some where that if that var is true, then run the mouse look script, so the mouse will be gone and moving the mouse controls looking, but if you hit the button again, it will be false and the mouse will appear, and moving the mouse will only allow you to click some things on the GUI and not move the screen. if someone could please write down the java script and/or explain how it works and stuff then please do

more ▼

asked Feb 15 '10 at 09:01 PM

Adam Bruns gravatar image

Adam Bruns
274 24 27 38

(comments are locked)
10|3000 characters needed characters left

3 answers: sort newest

There are 2 mouse look scripts that come with your first person controller. You would have to turn on/off both.

If you want to toggle mouse visibility and mouselook then try the following:

private var fpcMouse;
private var camMouse;

function Start () {

fpcMouse = gameObject.Find("First Person Controller").GetComponent("MouseLook");
camMouse = gameObject.Find("Main Camera").GetComponent("MouseLook");

}


function Update () {

if (Input.GetButtonDown ("Fire2")) {
    Screen.showCursor = !Screen.showCursor;
    fpcMouse.enabled = !fpcMouse.enabled;
    camMouse.enabled = !camMouse.enabled;
     }

}
more ▼

answered Feb 15 '10 at 09:36 PM

Sebas gravatar image

Sebas
4k 12 18 45

tried this one first, very simple and thank you it worked. to others who answered thank you as well

Feb 15 '10 at 10:08 PM Adam Bruns
(comments are locked)
10|3000 characters needed characters left

basically you should add 2 statements to your script.

void Update ()
{
if (Input.GetButtonDown("some button here"))
{
Screen.showCursor=!Screen.showCursor; //if true it will become not(true)=false and if false it will become true
this.enabled=!Screen.showCursor; //this is a reference to current script. you should add this
//to mouse look script to work. if this is another script then you should use GetComponent    
}

you should use GetComponent like this

var ml=GetComponent("MouseLook");

then you should use ml.enabled rather than this.enabled. if the MouseLook is in another gameObject use what sebas provided with your GameObject name.

more ▼

answered Feb 15 '10 at 09:53 PM

Ashkan_gc gravatar image

Ashkan_gc
9.1k 33 56 117

(comments are locked)
10|3000 characters needed characters left

basically you should add 2 statements to your script.

void Update ()
{
if (Input.GetButtonDown("some button here"))
{
Screen.showCursor=!Screen.showCursor; //if true it will become not(true)=false and if false it will become true
this.enabled=!Screen.showCursor; //this is a reference to current script. you should add this
//to mouse look script to work. if this is another script then you should use GetComponent    
}

you should use GetComponent like this

var ml=GetComponent("MouseLook");

then you should use ml.enabled rather than this.enabled. if the MouseLook is in another gameObject use what sebas provided with your GameObject name.

more ▼

answered Feb 15 '10 at 09:50 PM

Ashkan_gc gravatar image

Ashkan_gc
9.1k 33 56 117

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x984
x179
x64

asked: Feb 15 '10 at 09:01 PM

Seen: 1627 times

Last Updated: Feb 15 '10 at 09:29 PM