- Home /
how does unity input works for pc and android
actually i want to know that how unity reads input for PC games like (MouseButtonDown) and android touches . I am not talking about methods to use them , i am asking how they work . Can anyone explain it please. Reason is a issue in my game which i am unable to explain to explain .
Answer by zereda-games · Feb 18, 2019 at 11:41 AM
its referenced under Edit->BuildSetting->Input
Each axis has a main input and an alternative pre done for you. to access them directly through code you access them via a string pasthrough. aka Input.GetKey("Vertical"){} or Input.GetKey("Horizontal"){} Works similar to how SceneManager handles build index with strings. if the list of scenes has a scene with the name called it returns that scene by name for example. similar method applies here. because Vertical and Horizontal Exist within the Axis' list we can call it by string in an Input.GetKey() GetKeyDown() or GetKeyUp();
thanks for your reply. I am building a game like zig-zag and added a UI button Jump . So my player(Ball) should only change direction when we tap on screen , and it's working fine on pc as well . But after running on my android device it's not working as when i tap on UI the player's direction is also changing so please help. I am really in great confusion.
I saw a question on this exact issue the other day, i'll post when i find it. hang tight, and i'll try and be quick.
Link 1 https://answers.unity.com/questions/1473551/android-touch-input-not-working-in-build.html
Link 2 https://answers.unity.com/questions/1063429/problem-moving-a-gameobject-with-an-ondrag-event-w.html
Extra notes:
[Added] Link 3 https://docs.unity3d.com/ScriptReference/Input.GetTouch.html
[Added] Link 4 https://answers.unity.com/questions/647281/how-to-use-android-input.html
[Added] Link 5 https://docs.unity3d.com/$$anonymous$$anual/PlatformDependentCompilation.html
sorry but none are the one i was on the other day, but these may help you, sorry if not. hope you have some luck.
Answer by dan_wipf · Feb 18, 2019 at 11:48 AM
i can’t tell you exactly how it works, but there are several methods for several situations to keep in mind!
just fyi:
Input.something method => used at runtime no UI
event.current method => used for editor
ipointer method => used for UI elements
i believe there are more methods to add to this list those are just the common one i use in my projects