- Home /
MouseLook half disabling
Hello, I need help. I've made a script and I'll show you that soon but first, I need to elaborate on what's going on. Basically, I have a GUI which appears and the player can read it but do nothing else until they press "V", once they have, they are supposed to see the GUI disappear (and they do) but when they press "V" they can't look up or down, only left or right. If they press it again, another GUI shows up and they can type in a box an answer the the question asked in the first GUI. The problem is, whenever one of the GUIs are open, vertical movement of the mouse can be achieved and whenever they are closed, only horizontal movement in enabled. Not sure what I did wrong in my script. Just so you know, I think the problems are in the if and if else statements. `using UnityEngine; using System.Collections;
public class GuiUp : MonoBehaviour {
public bool guiUp;
public bool guiUpBack;
public Texture guiSkin;
public Texture guiSkinBack;
public string text;
public MouseLook mouseLook;
public MouseLook cameraMouseLook;
public GUIStyle style;
// Use this for initialization
void Start () {
mouseLook = GetComponent<MouseLook>();
cameraMouseLook = GetComponentInChildren<MouseLook> ();
Screen.showCursor = false;
guiUp = true;
Time.timeScale = 0f;
mouseLook.enabled = false;
cameraMouseLook.enabled = false;
}
void Update (){
if(guiUp == true){
guiUpBack = false;
}
if(Input.GetKeyDown(KeyCode.V) && guiUpBack == false && guiUp == true){
guiUp = false;
Time.timeScale = 1;
mouseLook.enabled = true;
cameraMouseLook.enabled = true;
}
else if(Input.GetKeyDown(KeyCode.V) && guiUpBack == false){
guiUpBack = true;
Time.timeScale = 0.0f;
Screen.showCursor = true;
mouseLook.enabled = false;
cameraMouseLook.enabled = false;
}
else if(Input.GetKeyDown(KeyCode.V) && guiUpBack == true){
guiUpBack = false;
Time.timeScale = 1.0f;
Screen.showCursor = false;
mouseLook.enabled = true;
cameraMouseLook.enabled = true;
}
}
void OnGUI (){
if(guiUp == true){
GUI.DrawTexture(new Rect(Screen.width/8f, Screen.height/10f, 1500f, 750f), guiSkin);
}
if(guiUpBack == true){
GUI.DrawTexture(new Rect(Screen.width/8f, Screen.height/10f, 1500f, 750f), guiSkinBack);
GUI.TextArea(new Rect(Screen.width/6f, Screen.height/4f, 1000f, 100f), text, style);
}
}
} That's my entire code, just in case I leave something important and you guys can't help me.
Also, if possible, could you tell me how to get my text are to work, I can't type anything in it. Thanks in advance!
Answer by unimechanic · Dec 10, 2014 at 06:04 PM
Please check the scripting tutorials:
https://unity3d.com/learn/tutorials/modules/beginner/scripting
I've checked the tutorials, actually, I've seen them all and written notes on them, but anyway, are you able to tell me the video that would help point me in the right direction? Thanks in advance