Quantcast
Channel: Questions in topic: "log"
Viewing all articles
Browse latest Browse all 235

Keyboards Input not working

$
0
0
I'm making a small 2D platformer game to learn the basics of programming in c# and I quickly encountered a problem. After writing the lines of code necessary for my character to move, I tested and nothing happenned. I know most would think it is an error with the script and I do not dismiss that but, there seems to be another problem going on. I wrote a small piece of script to detect input from a key and notify in the concole that it is working but, it's not working. I have tested the script with different keys and also with the horizontal axis but nothing works. Here is the script to notify me of the input working properly: if(Input.GetKey(KeyCode.A)) { Debug.Log("Working"); } This script is written in the update "section".( void update(){ here } ) p.s. There might be a very simple solution to this matter but I do not know of it. Edit: Here is the complete script of the controls for my character + the test debug script: (please note the values are values placed there temporarely and the values might be unsuited for an actual game but the problem that I have is stopping me from testing those values.) -–---- private Rigidbody2D myRigidBody; private float moveSpeed = 2f; private bool grounded; public float jumpHeight = 0f; public Transform groundcheck; void Start () { myRigidBody = GetComponent(); } // Update is called once per frame void Update () { grounded = Physics2D.Linecast(transform.position, groundcheck.position, 1 << LayerMask.NameToLayer("Ground")); if (Input.GetKeyDown(KeyCode.B) && grounded) { myRigidBody.velocity = new Vector2(0,jumpHeight); } if (Input.GetKey(KeyCode.Q)) { Debug.Log("Working"); } if (Input.GetKey(KeyCode.A)){ myRigidBody.velocity = new Vector2(moveSpeed * -1, 0); } if (Input.GetKey(KeyCode.D)){ myRigidBody.velocity = new Vector2(moveSpeed * 1, 0); } } } Edit2: I tried using the mouse buttons to see if anything works but it didn't work... seems like no inputs affecting the game are getting received. Edit3: It suddenly started working for no reason so I guess now everything's fine.

Viewing all articles
Browse latest Browse all 235

Trending Articles



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