Quantcast
Channel: Questions in topic: "keyboard"
Viewing all articles
Browse latest Browse all 605

If, GetKeyDown, and Update() not working

$
0
0
I'm using Visual Studio to compile this and i'm not sure why it isn't working. If I remove the GetKeyDown statement, the bool is always true and it works fine. As soon as I add it, the bool wont toggle and the float doen't increase. The label prints fine, the bool doen't change with the keypress. I have included more additional floats as a way to see whats functioning and whats not. I can see the number of calls/min of Update and FixedUpdate. The other floats outside of the conditional statements also stop changing when I add the GetKeyDown function. Can anyone help me out? using UnityEngine; using System.Collections; namespace menu { public class testmain : MonoBehaviour { private float updateCount = 0; private float fixedUpdateCount = 0; private float updateUpdateCountPerSecond; private float updateFixedUpdateCountPerSecond; private float stuff; private bool statsUp; private void Start() { } private void Awake() { stuff = 1; StartCoroutine(Loop()); statsUp = true; } private void Update() { updateCount += 1; if (statsUp) { stuff += 1f; } if (Input.GetKeyDown(KeyCode.Insert)) statsUp = !statsUp; } private void FixedUpdate() { fixedUpdateCount += 1; } private void OnGUI() { //x, y, width, height GUIStyle fontSize = new GUIStyle(GUI.skin.GetStyle("label")); fontSize.fontSize = 24; GUI.Label(new Rect(100, 100, 200, 50), "Update Calls/Sec: " + updateUpdateCountPerSecond.ToString(), fontSize); GUI.Label(new Rect(100, 150, 200, 50), "FixedUpdate Calls/Sec: " + updateFixedUpdateCountPerSecond.ToString(), fontSize); GUI.Label(new Rect(100, 300, 400, 50), "statsUp + stuff2 : " + statsUp.ToString() + " : " + stuff.ToString(), fontSize); } IEnumerator Loop() { while (true) { yield return new WaitForSeconds(1); updateUpdateCountPerSecond = updateCount; updateFixedUpdateCountPerSecond = fixedUpdateCount; updateCount = 0; fixedUpdateCount = 0; } } } } ![alt text][1] [1]: /storage/temp/152328-94h0yxglms.png This is the printed result. It looks like Update stops being called. It is showing 0 calls/sec

Viewing all articles
Browse latest Browse all 605

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>