Graphical glitch on mobile phone when tapping a button

Viewed 51

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:

Video of Glitch

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. In fact this is a test program I made only to show this glitch. This is literally all the code I wrote for the application:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
    public GameObject Button;
    Vector3 testStart;
    void Start()
    {
        testStart = new Vector3(Button.transform.position.x + 500, Button.transform.position.y);
    }
    public void MoveButton()
    {
        StartCoroutine(Move());
    }
    IEnumerator Move()
    {
        while (Button.transform.position.x != testStart.x)
        {
            Button.transform.position = Vector2.MoveTowards(Button.transform.position, testStart, 600f * Time.deltaTime);
            yield return null;
        }
    }
}

++++UPDATE++++

It might actually have something to do with events in general. I get a similar issue with an event trigger on a sprite animation on my actual game too. When I add this code to make the button move without an event trigger, it works just fine:

int intCounter = 0;
private void Update()
{
    if(intCounter == 260)
    {
        MoveButton();
    }
    else
    {
        intCounter++;
    }
}
0 Answers
Related