ive been having a problem with ctrl and a number not running the lines of code inside the braces.
it wont work inside the editor or after a build to an EXE.
i found someone having the same trouble and tried there solution but it didn’t seem to work for me.
i have also tried plugging in a USB keyboard to see if it’s my laptop thats causing the trouble. still same problem.
if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.Alpha1))
{
print("Doesn't print this");
}
or
if (Input.GetKeyDown("1"))
{
ControlGroup(1);
}
void ControlGroup (int number)
{
if ((Input.GetKey (KeyCode.LeftControl)) || (Input.GetKey (KeyCode.RightControl)))
{
switch(number)
{
case 1:
print ("Doesn't print this either");
break;
}
any ideas what i’m missing?
many thanks in advance
Try this; if (Input.GetKey(KeyCode.LeftControl) | Input.GetKeyDown(KeyCode.Alpha1))
– NidreThis is most strange, you are absolutely correct. I just did a test in uJS, and it had the exact problem you are describing. I even tried checking for a string instead of a keycode enum : function Update() { if ( Input.GetKey( KeyCode.LeftControl ) ) { Debug.Log( "LeftCtrl Detected" ); if ( Input.GetKeyDown( KeyCode.Alpha1 ) ) { Debug.Log( "LeftCtrl and Alpha1 Detected" ); } if ( Input.GetKeyDown( "1" ) ) { Debug.Log( "LeftCtrl and String 1 Detected" ); } } } Upvoting question.
– AlucardJayNo i haven't tested actually.I just written that the same way i do for Windows applications on C# so i thought this might help :) By the way i have no idea why you are telling that :)My point was using | instead of ||(Cause in c# apps(Wİndows form actually) this usage works for access modifier keys.(Ctrl + X + X...) > There is no problem using extra parenthesis, as long as they encapsulate the appropriate items.
– NidreWell as i said i didn't mentioned "(" so the change was simply "||" that to "|" according to the general c# usage. I wouldn't change parenthesis and send this as an answer :)
– NidreLook, there is no problem here, I just wanted to clarify that using | will throw a warning in Unity. And it didn't fix the problem.
– AlucardJay