- Home /
U.I. button event not working properly on android!
Hi, I'm a beginner in Unity and making my very first game for android. Since getting input in windows is easy I've this problem in android. I'm using gui button (testing with only one now) to move character. He works fine with simple onClick() but I want him to keep moving as long as the button is being pressed. So, I used onpointerdown() and onpointerup() event in Inspector, called my function through them. but the same problem persists, he just moves a little and stops even while holding the button (no obstacle in between). Look at my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerTest : MonoBehaviour
{
public Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
public void moveRight()
{
rb.velocity = Vector2.right * 5f;
}
public void stopMove()
{
rb.velocity = Vector2.zero;
}
}
That's it!! please help me
Your answer
Follow this Question
Related Questions
Unity2D quads not appearing in front of other quads in Android build 1 Answer
I have this problem when I restart my game in Unity, bunch of gameObject spawns at once 1 Answer
problem with the change's speed between 2 texture using a switch script, how can i speed it up? 1 Answer
Switch editor platform to android from WindowsEditor 0 Answers
can't enable wifi in unity on android device [duplicate] 1 Answer