When i press one button lets say left iworks but when i press jump the jump starts but left movement stops…
using UnityEngine;
using System.Collections;
public class touchControls : MonoBehaviour {
public GameObject player;
public bool movingleft = false;
public bool movingright = false;
public bool grounded;
public float jumpForce = 100;
public int finger1 = 1;
public int finger2 = 2;
public int finger3 = 3;
public int finger4 = 4;
public Touch touch;
Rigidbody2D rig;
void Start () {
rig = GameObject.FindGameObjectWithTag ("player").GetComponent<Rigidbody2D> ();
}
void Update () {
grounded = GameObject.FindGameObjectWithTag ("player").GetComponent<kontrola> ().ground;
if (grounded) {
//sr.sprite = gor;
} else if (!grounded) {
// sr.sprite = dol;
}
if (Application.platform == RuntimePlatform.Android) {
if (Input.touchCount > 0) {
for (int i=0; i<Input.touchCount; i++) {
if(Input.GetTouch (i).phase == TouchPhase.Began){
CheckTouch(Input.GetTouch(i).position, "begin");
}
else if(Input.GetTouch (i).phase == TouchPhase.Ended){
if(touch.fingerId == finger1){
finger1 = 1;
movingleft = false;
}
if(touch.fingerId == finger2){
finger2 = 2;
movingright = false;
}
if(touch.fingerId == finger3){
finger3 = 3;
}
}
}
}
}
if (movingleft) {
player.transform.Translate (Vector2.left * Time.deltaTime * 5f);
}
if (movingright) {
player.transform.Translate (Vector2.right * Time.deltaTime * 5f);
}
}
void CheckTouch(Vector3 pos, string phase){
Vector3 wp = Camera.main.ScreenToWorldPoint(pos);
Vector2 touchPos = new Vector2(wp.x, wp.y);
Collider2D hit = Physics2D.OverlapPoint(touchPos);
if (hit.gameObject.name == "levogor" && hit && phase == "begin"){
movingleft = true;
finger1 = touch.fingerId;
}
if (hit.gameObject.name == "desnogor" && hit && phase == "begin"){
movingright = true;
finger2 = touch.fingerId;
}
if (hit.gameObject.name == "jump" && hit && phase == "begin" && grounded) {
rig.AddForce (new Vector2 (0f, jumpForce));
finger3 = touch.fingerId;
}
}
}