Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Animation is not playing in touch mode

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

  1. mightyjumpsky

    mightyjumpsky

    Joined:
    Jan 14, 2019
    Posts:
    4
    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. }