- Home /
Using keyboard to control a dialog/shop
Hello together,
in our project, we have a shop. So far, so good. I can talk to the salesman by pressing the key for action (e.g. E/Enter) - this works. Now I can press E/Enter to choose, if I want to buy or sell something. At least I can buy Items with E/Enter.
To my problem:
If I have all three keyboard accesses with "isKeyDown" - it does not work.
It is skipping the buy/sell state and the customer instantly buy the first item.
If I mix the accsses with "isKeyDown" and "isKeyUp" it works half - it is possible to select buy/sell - but if I select buy, it still buys an item (the first).
Has anybody an idea to solve this "problem" or have an other approach?
Greetings,
v4mpy
Hello,
here is some example code to my problem:
using UnityEngine;
using System.Collections.Generic;
public class test : $$anonymous$$onoBehaviour
{
bool first;
void Start ()
{
}
void Update ()
{
if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.E)) {
Debug.Log ("First");
first = true;
}
if (first) {
if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.E)) {
Debug.Log ("Second");
}
}
}
}
Problem: Unity debugs "First" and "Second" but I only pressed one time the key.
I want: I need to press two times the key, for debugging first and second.
Greetings
Answer by V4mpy · Dec 06, 2013 at 08:01 PM
Just change the order of statements.
A B C becomes C B A.
Your answer
![](https://koobas.hobune.stream/wayback/20220613122540im_/https://answers.unity.com/themes/thub/images/avi.jpg)