Question by
Akatsura61 · Dec 17, 2016 at 02:30 PM ·
c#androidtouchjumpmultitouch
Two finger tap causes jump bug
Hi guys. I am making game for mobile devices. But i m pretty new in touch scripts. So i wrote a code that jumps the player. But when two finger hit the screen player jumps 2x more. I can't disable multitouch. Because there is two controls on screen. Half of screen jumps other halfs attacks. If i disable multitouch we cant attack at the same time jumping. Here is my code
Input.multiTouchEnabled = false;
if (Input.touchCount > 0)
{
for (int i = 0; i < Input.touchCount; i++)
{
Input.multiTouchEnabled = false;
Touch t = Input.GetTouch(i);
if (t.position.x > Screen.width / 2 )
{
Input.multiTouchEnabled = true;
if (t.phase == TouchPhase.Began)
{
anim.SetTrigger("Vur");
vurdi = true;
}
}
if (t.position.x < Screen.width / 2 )
{
Input.multiTouchEnabled = true;
if (t.phase == TouchPhase.Began )
{
if (grounded)
{
ziplaButonBasildi = true;
myRigidbody2D.AddForce(Vector3.up * jumpSpeed, ForceMode2D.Impulse);
anim.SetBool("Jump", !grounded);
}
if (gameObject.transform.position.y > 1f)
{
maximumZiplandi = true;
}
if (gameObject.transform.position.y < -1.58f)
{
maximumZiplandi = false;
}
}
if (t.phase == TouchPhase.Stationary || t.phase == TouchPhase.Moved)
{
if (ziplaButonBasildi == true)
{
Input.multiTouchEnabled = true;
if (gameObject.transform.position.y > 1f)
{
maximumZiplandi = true;
}
if (gameObject.transform.position.y < -1.58f)
{
maximumZiplandi = false;
}
if (maximumZiplandi == false)
{
if (jumpSpeed < maximumZiplamaMiktar)
{
myRigidbody2D.AddForce(Vector3.up * 10, ForceMode2D.Force);
}
}
}
}
if (t.phase == TouchPhase.Ended)
{
ziplaButonBasildi = false;
}
}
}
}
I tried somethings with multitouch but cant manage it. Any suggestions ?
Comment
Your answer
Follow this Question
Related Questions
Why is my multi touch not working? 1 Answer
Jump by touch Unity C# 0 Answers
Multitouch doesn't work 1 Answer
Replace TouchPhase.Ended with booleans? 1 Answer
buttons vs touch. 1 Answer