- Home /
Return Acting As Space(4.3.2)
So basically, I try to use
if(Input.GetKeyDown(KeyCode.Return)) {
print("It Worked!");
//Code stuff here, removed for example
}
And where it says code stuff here, I set bools and such, but when I use it and hit return(enter) it calls the print, but not the bool setting and such. But strangely, when i hit the space bar, it does all of it, as if the spacebar was return. This only happens in this script, no others, and I have tried making a new script, it did nothing. Im not sure if this is a bug, but it may be. This really annoying and I need to figure it out. Thanks!
This should work perhaps if you post the rest of the code we could get a better idea of what may be causing your issue
Oh yeah, sorry. here
using UnityEngine;
using System.Collections;
public class GraphicsOptionsTwo : $$anonymous$$onoBehaviour {
public GUISkin Skin;
public Player$$anonymous$$ey $$anonymous$$ey;
public int WhatOne;
public string[] AllTheOptions;
public bool BloomEnabled = true;
public bool LimitedFramesBool = true;
public string BloomEnabledString;
public string LimitedFramesString;
void Start() {
$$anonymous$$ey = GameObject.Find("$$anonymous$$eys").GetComponent<Player$$anonymous$$ey>();
}
void Update() {
if(BloomEnabled) {
BloomEnabledString = "Yes";
}
else {
BloomEnabledString = "No";
}
if(LimitedFramesBool) {
LimitedFramesString = "Yes";
}
else {
LimitedFramesString = "No";
}
if(Input.Get$$anonymous$$eyDown($$anonymous$$ey.Down)) {
WhatOne++;
if(WhatOne > 1) {
WhatOne = 0;
}
}
if(Input.Get$$anonymous$$eyDown($$anonymous$$ey.Up)) {
WhatOne--;
if(WhatOne < 0) {
WhatOne = 1;
}
}
}
void OnGUI() {
GUI.matrix = $$anonymous$$atrix4x4.TRS (Vector3.zero, Quaternion.identity, new Vector3 (Screen.width / 1280.0f, Screen.height / 720.0f, 1));
GUI.skin = Skin;
if($$anonymous$$enuGUIHandler.Can$$anonymous$$enuHideraphics) {
GUI.Label(new Rect(440, 50, 500, 100), "<size=30>Graphics Options</size>");
GUI.SetNextControlName("BloomEnabledSwitch");
if(GUI.Button(new Rect(476 - 100, 250, 400, 35), "Bloom [" + BloomEnabledString + "]", "$$anonymous$$ain$$anonymous$$enuButtons")) {
BloomEnabled = !BloomEnabled;
print("WAZZUP");
PlayerPrefsX.SetBool("Bloom", BloomEnabled);
}
if(GUI.GetNameOfFocusedControl() == "BloomEnabledSwitch" && Input.Get$$anonymous$$eyDown($$anonymous$$ey.Attack)) {
BloomEnabled = !BloomEnabled;
print("WAZZUP");
PlayerPrefsX.SetBool("Bloom", BloomEnabled);
}
GUI.SetNextControlName("FramesEnabledSwitch");
if(GUI.Button(new Rect(476 - 100, 350, 400, 35), "Limited Frames [" + LimitedFramesString + "]", "$$anonymous$$ain$$anonymous$$enuButtons")) {
LimitedFramesBool = !LimitedFramesBool;
print("Im BAC$$anonymous$$!!!");
PlayerPrefsX.SetBool("FrameRate", LimitedFramesBool);
}
if(GUI.GetNameOfFocusedControl() == "FramesEnabledSwitch" && Input.Get$$anonymous$$eyDown($$anonymous$$ey.Attack)) {
LimitedFramesBool = !LimitedFramesBool;
print("Im BAC$$anonymous$$!!!");
PlayerPrefsX.SetBool("FrameRate", LimitedFramesBool);
}
if(AllTheOptions.Length > 0) {
GUI.FocusControl(AllTheOptions[WhatOne]);
}
}
}
}
All I can think of is that OnGUI()
can be called multiple times per frame, so each event gets a chance to run. If, for bizarre reasons, your buttons get called multiple times, your inversion logic for BloomEnabled
etc might not work as you expect.
Your answer
Follow this Question
Related Questions
My scripts are not working properly 0 Answers
Why doesn't my if statement work? 1 Answer
Shift + KeyCode.Equals works in Unity Editor but not on WebGL build 0 Answers
Unity keeps crashing whenever I try to do anything! Please Help! 0 Answers
Why is root motion reduced once I apply the animation? 0 Answers