Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Change Source Image of a GameObject

Discussion in 'Scripting' started by ScamTheMan, May 11, 2020.

  1. ScamTheMan

    ScamTheMan

    Joined:
    Oct 4, 2018
    Posts:
    75
    Hello, I was wondering if there's some simple code to change Source Image of a game object from an array of Images. I know there's harder way to do it by stacking each Image on the same spot and then making them active (myImage[someInt].gameObject.SetActive(true)) but I want to know if you can just arrange an array of Images and then by code placing one of them on the Source Image of a game object.

    Thank you for any help.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    What do you mean by "Source Image" of a GameObject? Are you talking about a specific component such as SpriteRenderer or UnityEngine.UI.Image?
     
  3. ScamTheMan

    ScamTheMan

    Joined:
    Oct 4, 2018
    Posts:
    75
     

    Attached Files:

    • ggg.png
      ggg.png
      File size:
      11.1 KB
      Views:
      821
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
  5. ScamTheMan

    ScamTheMan

    Joined:
    Oct 4, 2018
    Posts:
    75
  6. Acromatic

    Acromatic

    Joined:
    Feb 2, 2021
    Posts:
    3
    Doesn't work like that in current versions, sprite was replaced with image.
     
  7. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    Nothing has changed in recent versions with Image and Sprite.