Search Unity

Animation is not playing in touch mode

Discussion in 'Animation' started by mightyjumpsky, Feb 7, 2019.

  1. mightyjumpsky

    mightyjumpsky

    Joined:
    Jan 14, 2019
    Posts:
    15
    Hello...
    Can someone help me, when i run my game on android, sometimes my jump animation is played sometime is not... When i run using computer, there's no problem.....Any help much appreciated.... Thanks..


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class playerAnim : MonoBehaviour
    6. {
    7.     public Animator anim;
    8.  
    9.     // Start is called before the first frame update
    10.     void Start()
    11.     {
    12.         anim = GetComponent<Animator>();
    13.     }
    14.  
    15.     // Update is called once per frame
    16.     void Update()
    17.     {
    18.         //touch screen
    19.           if (Input.touchCount > 0)
    20.          {
    21.          Touch touch = Input.GetTouch(0);
    22.  
    23.  
    24.  
    25.          if (touch.position.x > Screen.width / 2 && touch.phase == TouchPhase.Began)
    26.         //if (Input.GetKeyDown(KeyCode.RightArrow))
    27.         {
    28.             anim.SetBool("isFlying", true);
    29.             anim.SetBool("isIdle", false);
    30.  
    31.         }
    32.  
    33.  
    34.         else if (touch.position.x < Screen.width / 2 && touch.phase == TouchPhase.Began)
    35.         //else if (Input.GetKeyDown(KeyCode.LeftArrow))
    36.         {
    37.             anim.SetBool("isFlying", true);
    38.             anim.SetBool("isIdle", false);
    39.  
    40.         }
    41.  
    42.         else
    43.         {
    44.             anim.SetBool("isFlying", false);
    45.             anim.SetBool("isIdle", true);
    46.         }
    47.     }
    48. }  
    49. }