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

Properly way to read keyboard input

$
0
0
I've been developing unity for 2 days and I'm still stuck at the keyboard input part. I mean, take a look at my code: function Update () { if(Input.GetKey (moveLeft)) if(Input.GetKey(run)) rigidbody2D.velocity.x = fastSpeed*-1; else rigidbody2D.velocity.x = normalSpeed*-1; else if(Input.GetKey (moveRight)) if(Input.GetKey(run)) rigidbody2D.velocity.x = fastSpeed; else rigidbody2D.velocity.x = normalSpeed; else if(Input.GetKey(jump)) rigidbody2D.velocity.y = normalSpeed; else rigidbody2D.velocity.x = 0; } So, I know it's a pretty lame question but as far as I researched I couldn't find an answer that satisfies my doubt..What's the properly way to read keyboard inputs on unity? I'm developing a 2D game and since it's a small project I could handle multiple entries combining keys as I did, but on bigger projects how do they do this? With this code I can run with a normal and fast speed, but for example,I can't run with a fast speed and jump at the same time so I would like to understand how does this work on projects with tons of entries? Thanks

Viewing all articles
Browse latest Browse all 605

Trending Articles



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