Move an object when holding down 3 keys, But only using 2?
I am making a guitar hero style game, And im making it so when i press 1 and backspace together, the fret will bounce up. I also want to do this to 4 other frets. When im holding 1 and backspace only, it works as it should, But when i hold 1 and 2 + backspace, It wont work.
if(Input.GetKeyDown(KeyCode.Backspace) && Input.GetKey(KeyCode.Alpha1){
FretPositionGreen = 2;
greenFret.transform.localPosition.y = 0.0006;
}
if(Input.GetKeyDown(KeyCode.Backspace) && Input.GetKey(KeyCode.Alpha2){
FretPositionRed = 2;
RedFret.transform.localPosition.y = 0.0006;
}
This is a simple logic problem.
You used get$$anonymous$$eyDOWN for backspace. This will only happen for one frame. So the user would have to press all three keys exactly at the same time.
Use normal Get$$anonymous$$ey to avoid this.
PS; Don't make overly complicated key combinations, many keyboard manufacturers put some buttons on the same circuit to save costs. It might not be possible for the user to press a certain combination on their keyboard.
See this question to explain what i mean:
Dang thats a bummer :( Is there any work around?, At the moment i can press 12345 all at the same time ( im using a wireless mac keyboard ), $$anonymous$$aybe it could be my coding? ill post the whole thing here :
function Update (){
if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.Alpha1)){
Green$$anonymous$$eyActive = true;
greenFret.transform.localPosition.y = -0.0075;
}else{
greenFret.transform.localPosition.y = -0.0034323455;
}
if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.Alpha2)){
Red$$anonymous$$eyActive = true;
RedFret.transform.localPosition.y = -0.0075;
}else{
RedFret.transform.localPosition.y = -0.0034323455;
}
if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.Backspace)){
if(Green$$anonymous$$eyActive == true){
if(green_Hit == true){
FretPositionGreen = 2;
greenFret.transform.localPosition.y = 0.0006;
}
}
if(Red$$anonymous$$eyActive == true){
if(Red_Hit == true){
FretPositionRed= 2;
RedFret.transform.localPosition.y = 0.0006;
}
}
}
}
Damnit, sorry for reacting so late. $$anonymous$$y Unity answers folder had about 130 new emails. :/
I would not recommend using a keyboard, but rather a game controller, like xbox 360 for PC. They are guaranteed to being able to scan every button simultaneously so there should be no problem getting that to work. But the handling is different of course.
If you want to use 2+ key combinations on keyboard, make sure the user can test if that works for their keyboard, if it doesn't let them assign keys that fit their specific keyboard.
Again, you have no way to find out what keyboard the player has and what its limitations are. Therefore I don't believe there is a workaround using a keyboard approach and you want to scan many keys at the same time.
Your answer
Follow this Question
Related Questions
How to rotate cube2 if the script is in cube1? 1 Answer
How add(create) a new gameobject on scene on mouse button click. 2 Answers
Missing Reference. 0 Answers
how to make a level block/unblock 1 Answer
Need a Script for Changing Scenes after pressing E to open locked door once a key has been found. 0 Answers