check if E key is pressed in c#

Can someone help, I just want to know when the E key is pressed for picking up objects. I am using mouse down as a placeholder, but that will be used for weapons, I found tutorials for Shift, LControl, and Enter, but no letters/numbers.

Try this in Update:

if (Input.GetKeyDown(KeyCode.A))
{
    //weapon stuff here
}
2 Likes

I would recommend using KeyCode.E though.

8 Likes

Definitely

Three years + later?

Yep, I came across this when I was looking for code to check for specific key input, as I am new to programming (I only just got unity today), and the method I found in a video just resulted in an error message.

1 Like

Don’t necro old threads please.

There is a learn section. It’s a bit hidden but here’s a direct link:

https://learn.unity.com/courses

Sorry, but thanks for the link anyway. I will not post on this thread again.

I am having problems it keeps saying Error CS1513
but i have all the brakets in the right places see
public class PlayerMovment : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.A));
{

}

else (Input.GetKeyDown(KeyCode.D));
{

}
else if (Input.GetKeyDown(KeyCode.W));
{

}
}
}

IF Statements - Unity Learn

1 Like

PLEASE do not reply to four year old random threads with unrelated questions. It is against forum rules.

Instead, start your own fresh post… it is FREE. When you do, keep these things in mind:

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

How to understand compiler and other errors and even fix them yourself:

https://forum.unity.com/threads/assets-mouselook-cs-29-62-error-cs1003-syntax-error-expected.1039702/#post-6730855

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379

2 Likes