- Home /
help please :S? im confusing myself.
hey guys :)
i feel ashamed that im confusing myself here :) and im probably over thinking but heres what im trying to do.
Lock the cursor to the middle of the screen Hide the cursor when not in a dialog/gui Press e on a cylinder, it pops up with a GUI, unhide the cursor and unlock the cursor Press a button on the GUI and it closes the GUI menu, Hides and unlocks the cursor.
this is what iv managed to do: Confuse myself Hide the cursor (i had it locked but i wrecked it) When you click the screen it unhides the cursor (unintentional) When you click the button on the GUI it doesnt lock or hide the cursor.
all this may seem like i have no idea what im doing..but i do, iv just confused myself and you will see how when you look at the code:
Script attached to the player object:
var LightToggled : boolean = false; var IsPaused : boolean = false; var Lockit : boolean = true; var Showit : boolean = false;
function Start() { };
function Update() { Screen.showCursor = Showit; Screen.lockCursor = Lockit;
if (Input.GetKeyDown ("f")){
if (LightToggled == true){
LightToggled = false;
}
else{
LightToggled = true;
};
};
GameObject.Find('Player').GetComponent('Light').enabled = LightToggled;
if (Input.GetKeyDown ("escape")){
PauseGame();
};
};
function OnGUI() {
GUI.Box(Rect(Screen.width/2, Screen.height/2-15, 1, 1), '');
if (IsPaused == true){
var ResumeButton : boolean = GUI.Button(Rect(Screen.width/2, Screen.height/2, 175, 20), "Resume Game");
var VisitWebsite : boolean = GUI.Button(Rect(Screen.width/2, Screen.height/2 + 25, 175, 20), "Visit the Website");
var MainMenu : boolean = GUI.Button(Rect(Screen.width/2, Screen.height/2 + 25 + 25, 175, 20), "Main Menu");
var QuitButton : boolean = GUI.Button(Rect(Screen.width/2, Screen.height/2 + 25 + 25 + 25, 175, 20), "Exit");
GameObject.Find('Player').GetComponent('MouseLook').enabled = false;
GameObject.Find('Player').GetComponent('CharacterMotor').enabled = false;
if (QuitButton){
Application.Quit();
};
if (ResumeButton){
IsPaused = false;
Time.timeScale = 1.0;
Screen.showCursor = false;
};
if (VisitWebsite){
Application.OpenURL("www.google.com");
};
if (MainMenu){
Application.LoadLevel(0);
};
}
else{
GameObject.Find('Player').GetComponent('MouseLook').enabled = true;
GameObject.Find('Player').GetComponent('CharacterMotor').enabled = true;
return;
};
};
function PauseGame() { if (IsPaused == true){ IsPaused = false; Screen.showCursor = false; Screen.lockCursor = true; } else{ IsPaused = true; Screen.showCursor = true; Screen.lockCursor = false; };
};
Script attached to the NPC (Cylinder):
var LookingAt : boolean = false; var QuestMenu = false; var Swsi : boolean = false; // should we show it var Swli : boolean = true; // should we lock it
var Player : GameObject; var proximity : int = 3;
var dist = Vector3.Distance(Player.transform.position, transform.position);
function Update() {
GameObject.Find('Player').GetComponent('Player').Lockit = Swli;
GameObject.Find('Player').GetComponent('Player').Showit = Swsi;
if (dist < proximity) {
if (Input.GetKeyDown ("e") && LookingAt == true){
QuestMenu = true;
}
else{
return;
};
};
};
function OnGUI() {
GameObject.Find('Player').GetComponent('MouseLook').enabled = false;
GameObject.Find('Player').GetComponent('CharacterMotor').enabled = false;
if(QuestMenu == true){
Swli = false;
Swsi = true;
GUI.Box(Rect((Screen.width/2) - (150/2), Screen.height/2, 150, 75), "Hi :D");
if (GUI.Button(Rect((Screen.width/2) - (150/2) + 5, Screen.height/2 + 30 , 140, 25), "Hai :D")){
QuestMenu = false;
Swsi = false;
Swli = true;
GameObject.Find('Player').GetComponent('MouseLook').enabled = true;
GameObject.Find('Player').GetComponent('CharacterMotor').enabled = true;
};
Swsi = true;
Swli = false;
}
else{
return;
};
};
function OnMouseEnter() { LookingAt = true; };
function OnMouseExit() { LookingAt = false; };
if you can shorten the code but still make it work and/or fix the problem/s that would be much appreciated :) thank you
Answer by Gambit 3 · Mar 24, 2011 at 12:58 PM
k i fixed it a little...still the bug where, when you spawn your mouse isnt in the center..you click and its off the screen.
i should add that im testing this in unity..im not compiling it an running it.
new code for the cylinder:
var LookingAt : boolean = false; var QuestMenu = false; var Swsi : boolean = false; // should we show it var Swli : boolean = true; // should we lock it
var Player : GameObject; var proximity : int = 3;
var dist = Vector3.Distance(Player.transform.position, transform.position);
function Update() {
GameObject.Find('Player').GetComponent('Player').Lockit = Swli;
GameObject.Find('Player').GetComponent('Player').Showit = Swsi;
if (dist < proximity) {
if (Input.GetKeyDown ("e") && LookingAt == true){
QuestMenu = true;
}
else{
return;
};
};
};
function OnGUI() {
if(QuestMenu == true){
Swli = false;
Swsi = true;
GameObject.Find('Player').GetComponent('MouseLook').enabled = false;
GameObject.Find('Player').GetComponent('CharacterMotor').enabled = false;
GUI.Box(Rect((Screen.width/2) - (150/2), Screen.height/2, 150, 75), "Hi :D");
if (GUI.Button(Rect((Screen.width/2) - (150/2) + 5, Screen.height/2 + 30 , 140, 25), "Hai :D")){
QuestMenu = false;
GameObject.Find('Player').GetComponent('MouseLook').enabled = false;
GameObject.Find('Player').GetComponent('CharacterMotor').enabled = false;
Swsi = false;
Swli = true;
};
}
else{
return;
};
};
function OnMouseEnter() { LookingAt = true; };
function OnMouseExit() { LookingAt = false; };
Oh yes, i forgot to add in the original post that when you press escape...you cant see the mouse :( and when you click the buttons nothing happens
Answer by Joshua · Apr 30, 2011 at 03:33 AM
"k i fixed it a little...still the bug where, when you spawn your mouse isnt in the center..you click and its off the screen."
function Start () {
Screen.lockMouse = true;
}
Your answer
