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. Dismiss Notice

Need Image in UI canvas to change depending on variable

Discussion in 'UGUI & TextMesh Pro' started by MJG1123, May 7, 2015.

  1. MJG1123

    MJG1123

    Joined:
    Apr 12, 2015
    Posts:
    24
    So I've been using

    public Text text1;

    to change the text on a button in the UI for my game according to a variable,
    now I need to do the same but for an image or image source on the same UI


    so I'm looking for something like

    public Image image1;

    image1(?) = (?)

    OR if you have a better Idea let me know. Screenshot (14).png canvas.
     
  2. shadow-river

    shadow-river

    Joined:
    May 29, 2013
    Posts:
    63
    use a switch statement that switch's by what is in your text1 string.

    sorry for the layout my browsers doing weired things will fix it when I get home.

    public void whatever your public void is on your buttons()
    {
    Switch(text1.text)
    {
    case "Kick":
    change image here

    break;

    case "Button"
    change image here

    break;


    }
    }

    don't know exactly what your wanting or how your scripts set up so sorry if this isn't what your wanting
     
  3. MJG1123

    MJG1123

    Joined:
    Apr 12, 2015
    Posts:
    24
    SO I guess more specifically is I have a system set up to generate creatures pokemon style, they have a state sheet like

    Name: (name)
    Class Image: (image) <-( I wanna to set a method that will make the currentSprite or currentImage this and loads it into the battle screen)
    Attack: (value)
    etc