Spell-Crafting
terrablade
—
2016-08-04T05:46:39Z —
#1
Hi I'm new to java script so this is probably really easy but is there a way to detect a key press such as the up arrow.
This is my current code.
function onCreate()
{
orb.setVelocity( 10 );
if(eval((Input.GetKey(KeyCode.KeyUp)))){
orb.TurnUp(5);
}
}
Amulgagar
—
2016-08-04T07:12:45Z —
#2
Yep, that should work. Looks like you're missing a semicolon inside of your Eval; fix that and you should be good to go.
terrablade
—
2016-08-05T04:24:41Z —
#3
I tried that still didn't work.
This is the error message I get.
ERROR:spell1:Spell error when trying to execute function (onCreate):
ReferenceError: Input is not defined
I'm guessing that the error is that CodeSpells doesn't know KeyUp?
Amulgagar
—
2016-08-05T05:02:48Z —
#4
Ah, yeah. Unity doesn't use "KeyUp". Instead you can either use Input.GetKey("up"); or Input.GetKey(KeyCode.UpArrow);. Here's the Unity documentation on Input.GetKey(): https://docs.unity3d.com/ScriptReference/Input.GetKey.html
KeyUp is an event that occurs when a key is released. So, you can use Input.GetKeyUp("up"); to check whether the key is being released. It is an event that occurs during the frame that a key is released.
terrablade
—
2016-11-03T22:22:22Z —
#5
OK. Thanks. Sorry for the late reply.