Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Animation glitch on mobile phone when tapping a button

Discussion in 'Animation' started by vandel212, Aug 30, 2020.

  1. vandel212


    May 10, 2020
    I'm running into a strange issue with my 2D game, it seems to revolve around animations. Here is an example of what happens when I tap a button:

    All it does is move the button to the right. When I do it though the game freezes, but it seems like stuff is still processing because after a fraction of a second it catches up. It only happens once as far as I can tell, after that, it never happens again. It only happens my phone (Moto X4), not on my computer. I'm not doing anything complicated. This is literally all the code I wrote for the application:

    This is a test program I made only to show this glitch.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class Test : MonoBehaviour
    5. {
    6.     public GameObject Button;
    7.     Vector3 testStart;
    8.     void Start()
    9.     {
    10.         testStart = new Vector3(Button.transform.position.x + 500, Button.transform.position.y);
    11.     }
    12.     public void MoveButton()
    13.     {
    14.         StartCoroutine(Move());
    15.     }
    16.     IEnumerator Move()
    17.     {
    18.         while (Button.transform.position.x != testStart.x)
    19.         {
    20.             Button.transform.position = Vector2.MoveTowards(Button.transform.position, testStart, 600f * Time.deltaTime);
    21.             yield return null;
    22.         }
    23.     }
    24. }