Dividing touch screen into two touch buttons
Hey i just working on a 2d game. I can control my game from computer easily but i can't control it on mobile devices. I need two control buttons or right side/left side of screen. One button or screen side will run attack. And the other button or screen side will work like GetKey and GetKeyDown.
if (Input.GetKeyDown(KeyCode.Space) && grounded)
{
myRigidbody2D.AddForce(Vector3.up * jumpSpeed, ForceMode2D.Impulse);
anim.SetBool("Jump", !grounded);
}
if (gameObject.transform.position.y > 1f)
{
maximumJumped = true;
}
if (gameObject.transform.position.y < -1.58f)
{
maximumJumped = false;
}
if (Input.GetKey(KeyCode.Space) && maximumJumped==false)
{
if (jumpSpeed<maximumJumpValue)
{
myRigidbody2D.AddForce(Vector3.up * 10, ForceMode2D.Force);
}
}
i need to do the same work like my space key does on touch screens left or right side. I tried to add two UI buttons. But i can't script held down event. Even tried event trigger. But i can't managed. Any suggestions ?
Now i added a button with event trigger on it. It have pointer down and pointer up events. And they connected to this code public void onJumpDown() {
if (grounded)
{
myRigidbody2D.AddForce(Vector3.up * jumpSpeed, Force$$anonymous$$ode2D.Impulse);
anim.SetBool("Jump", !grounded);
jumpWait = true;
}
if (gameObject.transform.position.y > 1f)
{
maximumJumped = true;
}
if (gameObject.transform.position.y < -1.58f)
{
maximumJumped = false;
}
if (maximumJumped == false)
{
if (ziplaWait == true)
{
if (jumpSpeed < maximumJumpValue)
{
myRigidbody2D.AddForce(Vector3.up * 10, Force$$anonymous$$ode2D.Force);
}
}
}
}
public void onJumpUp()
{
jumpWait = false;
}
But this didn't worked too
Your answer
![](https://koobas.hobune.stream/wayback/20220612102646im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Android detection not detected by android phone 0 Answers
Making a list of images within a scrollrect generated from prefabs tappable/clickable 1 Answer
PlayerPrefs not debugging 1 Answer
How to make a system in unity 0 Answers
My method is being repeated several times during a single input. 1 Answer