- Home /
Getting keyboard Input
Hello, How does one get keyboard input? If I have a script that detects when "F" is pressed it will turn the flashlight off?
Here's my code:
private var on = false;
function Update(){
if(Input.GetButtonDown("[F]")){
if(on){ light.intensity =0; on = false; } else { light.intensity =2; on = true; } } }
Answer by purplelilgirl · Sep 05, 2012 at 01:42 AM
Hi,
Accdg. to http://docs.unity3d.com/Documentation/Manual/Input.html and http://docs.unity3d.com/Documentation/ScriptReference/Input.html
Input.GetKey ("f");
Returns true while the user holds down the "f" key. Think auto fire.
Input.GetKeyDown ("f");
Returns true during the frame the user starts pressing down the "f" key.
Input.GetKeyUp ("f");
Returns true during the frame the user releases the "f" key.
Answer by chrisall76 · Sep 05, 2012 at 01:39 AM
if you want to find a button you have already defined:
if(Input.GetButtonDown("buttonnme")){
}
if you want to find a key not defined in your input settings:
if(Input.GetKeyDown(KeyCode.key)){
}
if(Input.Get$$anonymous$$eyDown($$anonymous$$eycode.key))
Should be
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.key))
Note the capital C in $$anonymous$$eyCode.
Answer by himanshugupta159 · Feb 05, 2019 at 06:27 AM
Check the below link it will explain the basic of input from keyboard https://unfragilecoding.blogspot.com/2019/02/keyboard-input-in-your-game.html
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
My distance variable is not changing? 2 Answers
A node in a childnode? 1 Answer
Blender Animations not working properly. 1 Answer
What is wrong with this? 1 Answer