- Home /
Touch controls creates problem to my code
Hello everyone, I'm using TouchPhase to register touch input on screen and everything works fine.
But for some reason, NOTHING in my code will be executed if I don't put a finger on the screen. (for example the automatic rigidbody.addforce won't be added before I touch the screen). So it seems that the "frames" or whatever doesn't get updated before the screen registers a touch input.
Video that explains everything and examples: Youtube Video presenting the problem (good to watch)
Example of using touch input in my code (this is for the jump function):
void Update () {
foreach(Touch touch in Input.touches){
//touchingPlatform is a bool checking if player is grounded, jumpButton is the GUItexture used for the jump button
if(touchingPlatform && touch.phase == TouchPhase.Stationary && jumpButton.HitTest (touch.position)){
rigidbody.AddForce(jumpVelocity, ForceMode.VelocityChange);
touchingPlatform = false;
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613103606im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Input.Touch gui.Texture button positioning off 0 Answers
Swipe horizontally and hold finger down to move character? 1 Answer
How to detect touch on a 3d object? 0 Answers
player moving on the x axis with the finger does not work 0 Answers
two finger touch always detects one finger touch first 1 Answer