- Home /
Input.inputString not detecting mouse action?
Hi,
well I'm making a Input Manager... I'm on the GUI, and I want to set the values by clicking a button and saving the next movement...
So, I use Input.inputString, the problem is that when I click on anywhere, the inputString returns a null value, is there any other variables that returns the mouse values?
public static Dictionary<string, KeyCode> inputMap;
//Start()
inputMap = new Dictionary<string, KeyCode>();
tempInputMap.Add("Fire1", (KeyCode)System.Enum.Parse(typeof(KeyCode), "Mouse0")); //Charges those values with a for cicle extracted from a file
tempInputMap.Add("Fire2", (KeyCode)System.Enum.Parse(typeof(KeyCode), "Mouse0")); //Charges those values with a for cicle extracted from a file
tempInputMap.Add("Fire3", (KeyCode)System.Enum.Parse(typeof(KeyCode), "Mouse0")); //Charges those values with a for cicle extracted from a file
//OnGUI()
foreach(KeyValuePair<string, KeyCode> input in tempInputMap) {
string strInputValue = Enum.GetName(typeof(KeyCode), input.Value);
GUI.Label(new Rect(10, 50*i+5, 500-30-100-100, 40), input.Key, labelCentered);
if(GUI.Button(new Rect(500-20-100-100, 50*i+5, 100, 40), strInputValue) && !tempInputMap.ContainsValue(KeyCode.None)) {
tempInputMap[input.Key] = KeyCode.None;
} else if(tempInputMap.ContainsValue(KeyCode.None) && Input.anyKey) {
string[] SearchKeyByValue = tempInputMap.Where(x => x.Value == KeyCode.None).Select(pair => pair.Key).ToArray();
tempInputMap[SearchKeyByValue[0]] = (KeyCode)Enum.Parse(typeof(KeyCode), Input.inputString, true);
}
GUI.Button(new Rect(500-10-100, 50*i+5, 100, 40), "Reset");
i++;
}
Thanks in advance. Bye.
Answer by Graham-Dunnett · Apr 17, 2014 at 02:04 PM
http://docs.unity3d.com/Documentation/ScriptReference/Input-inputString.html
It's documented that this function returns the string that was entered in the current frame. If your user is busy with the mouse, then it's unlikely that they are entering any string. Maybe you want to capture the last entered string in an Update function and store that for use in your GUI.
Oh, well I didn't remebered that I can use Event.current.keyCode in OnGUI function :P
Your answer
Follow this Question
Related Questions
Word or string position under mouse position 1 Answer
C# inputString mouse Keys? 1 Answer
Input.GetAxisRaw("Mouse ScrollWheel") 4 times 0 Answers
Checking whether string is a valid Input.Key 1 Answer
Left Click While Holding Right Click 1 Answer