- Home /
Invert mouse control
So I'm trying to make a options menu for my game where you could change mouse controls to inverted by pressing that button. Here's the code for how I'm making the button. I would love if someone could help me and show how it's done.
So basicly: You press that Invert Mouse button and mouse gets inverted, but I don't have any clue how to do this and couldnt really find anything useful from UnityAnswers or Unity Script Reference.
function OnGUI ()
{
GUI.DrawTexture(Rect(Screen.width/2-(texturewidth/2*x), Screen.height/2-(textureheight*y), texturewidth*x, textureheight*y), texture);//Draw Tex
if(GUI.Button(Rect(Screen.width/2-(buttonwidth/2*x), Screen.height/2, buttonwidth*x, buttonheight*y),"Invert Mouse"))//Draw button
//Invert mouse on/off code here
if(GUI.Button(Rect(Screen.width/2-(buttonwidth/2*x), Screen.height/2+(buttonheight*2*y), buttonwidth*x, buttonheight*y),"Back to Main Menu"))//Draw button
Application.LoadLevel("Main Menu");//Back to mainmenu
}
The only answer I've gotten wasnt anywhere near what I need so.... Anyone, Please read my message and answer to what I need and not with what I do not need.
Hey here's a tutorial for mouse invert (Freshly made):
Answer by $$anonymous$$ · Feb 17, 2014 at 12:43 AM
This is an old question but I'm just responding for anyone else that may find it when looking for a way to do this. I'm new to unity so I'm not sure if this is the best way to do it but it works for my purposes. I added a public Boolean variable called invertY in the MouseLook script that is on the main camera and used it like this to invert the camera.
if(invertY)
rotationY += Input.GetAxis("Mouse Y") * -sensitivityY;
else
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
In the menu script I did the following to get a button to control the invertY variable:
if(GameObject.FindGameObjectWithTag("MainCamera").GetComponent().invertY){
if(GUILayout.Button("Inverted"))
GameObject.FindGameObjectWithTag("MainCamera").GetComponent<MouseLook>().invertY = false;
}
else
if(GUILayout.Button("Normal"))
GameObject.FindGameObjectWithTag("MainCamera").GetComponent<MouseLook>().invertY = true;
Answer by Berenger · Jan 12, 2012 at 04:24 PM
I don't know if you the OS mouse position is read / write, but I guess it's not. Based on that, you should draw your own cursor (http://www.unifycommunity.com/wiki/index.php?title=Custom2DPointer. The website seems to be down right now, so here is mine in c# with modifications http://dl.free.fr/n5LkCHwtg).
Then in case of inversion, just invert the mousePos
$$anonymous$$aybe I didnt understand what you did mean, but that's not the one I need. I just need to know how to change mouse to inverted by pressing that button i've created.
Your answer
Follow this Question
Related Questions
Sidescroller Bullets Follow Mouse After Being Shot 2 Answers
rotation based on mouse position 2 Answers
Having both mouse orbit and smooth follow work at the same time? 0 Answers
Detecting Mouse Scroll Wheel? 2 Answers
Input Axis Mouse ScrollWheel 1 Answer