When i drag my finger on the left side of the screen the gameobject moves according to the drag. But when i touch the right side of the screen(where the jump object is (invisible)) , then the gameobject stops and it doesn’t jump. Can anybody help me?
void Start () {
posLine = GameObject.Find ("Main Camera").transform.position.x;
rigidbody2D = GameObject.Find("player").GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
time ++;
}
void FixedUpdate(){
for(int i=0; i< Input.touchCount;i++){
if((Input.GetTouch(i).phase == TouchPhase.Moved || Input.GetTouch(i).phase == TouchPhase.Began || Input.GetTouch(i).phase == TouchPhase.Stationary))
{
myRay = Camera.mainCamera.ScreenPointToRay(Input.GetTouch(i).position);
{
if (Physics.Raycast(myRay, out rayHit ))
{
if(rayHit.collider.tag == "move")
{
for (int ii = 0; ii < Input.touchCount; ++ii) {
Touch touch2 = Input.GetTouch(ii);
if (touch2.phase == TouchPhase.Began) {
touch1 = touch2.position.x;
}
if (touch2.phase == TouchPhase.Moved || touch2.phase == TouchPhase.Stationary) {
if(touch2.position.x > touch1){
GameObject.Find ("player").transform.Translate (Vector3.right * moveSpeed * (Time.deltaTime) * 5);
}
if(touch2.position.x < touch1){
GameObject.Find ("player").transform.Translate (Vector3.left * moveSpeed * (Time.deltaTime) * 5);
}
}
}
}
if(rayHit.collider.tag == "jump"){
if (time > 70) {
GameObject.Find ("player").rigidbody2D.AddForce (transform.up * jumpPower);
time = 0;
}
}
}
}
}
}
}
}
Thanks