- Home /
[ASNWERED] How To Change Button To An Alphabet Key
Hello everyone!
I need some help trying to change the input key of this java script so that it can use an alphabet key (a, b, c) instead of using a mouse key (Fire1, Fire2). Here is my code:
var projectile : Rigidbody;
var speed = 20;
function Update()
{
if( Input.GetButtonDown( "Fire3" ) )
{
var instantiatedProjectile : Rigidbody = Instantiate(
projectile, transform.position, transform.rotation );
instantiatedProjectile.velocity =
transform.TransformDirection( Vector3( 0, 0, speed ) );
}
}
What I was wondering was how do I change the "Fire3" key (which is the middle mouse button) to an alphabet key (a, b, c)? I have tried putting "a" instead of "Fire3" but then I get errors from Unity.
Thanks in advance for your help.
Answer by GuyTidhar · Apr 08, 2012 at 07:28 AM
You need to change the function itself:
Instead of
if (Input.GetButtonDown("Fire3"))
Do:
if (Input.GetKeyDown(KeyCode.A))
Answer by OzzyRawrz · Apr 08, 2012 at 09:21 AM
Its easy just use Input.GetKey(KeyCode.W) or Whatever key you want like Input.GetKey(KeyCode.Up) you can use GetKeyDown or GetKeyUp instead of GetKey just play around with them you will understand.