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

Unity UI Switching Image sprite overtime with CoRoutine causing weird artifacts

Discussion in 'Unity UI & TextMesh Pro' started by darcmagik, Dec 6, 2018.

  1. darcmagik


    Nov 22, 2018
    Hey everybody this is my first post on these forums so please be patient with me if I am doing something against normal routine. I'm working on a game right now and one piece is creating me a headache here. I am trying to at the beginning of the game when it first loads show a series of images for example the company logo and a few other logo's. I'm using an Image UI component and through a CoRoutine I change the image that is displayed after a 5 second delay. It works fine but there is a weird glitch where after it switches from the first image to the second image it shows the second one fine but it occasionally flashes with the first image. Its the same problem when it switches to the next one as well. I'm wondering if anybody has any ideas for me on this one.

    Here is how I'm doing it in code in case this will help figure out the root problem:
    Code (CSharp):
    1. void Start () {
    2.         if (bannerSprites.Length > 0)
    3.         {
    4.             Debug.Log("Called in Start");
    5.             if (bannerImageHolder != null)
    6.             {
    7.                 bannerImageHolder.GetComponent<Image>().sprite = bannerSprites[0];
    8.             }
    9.         }
    10.         else
    11.         {
    12.             SceneManager.LoadScene(1);
    13.         }
    14.     }
    16.     // Update is called once per frame
    17.     void Update () {
    18.         StartCoroutine(ChangeBanner());
    20.         if (doneShowingBanners)
    21.         {
    22.             SceneManager.LoadScene(1);
    23.         }
    24.     }
    26.     IEnumerator ChangeBanner()
    27.     {
    28.         for (int bannerCount = 0; bannerCount < bannerSprites.Length; bannerCount++)
    29.         {
    30.             bannerImageHolder.GetComponent<Image>().sprite = bannerSprites[bannerCount];
    31.             yield return new WaitForSeconds(waitTime);
    32.         }
    33.         doneShowingBanners = true;
    34.     }
    Thanks for any help you can all provide me.