Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  3. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    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 at 5:16 PM.

  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.