Change Sprite image when Unity is clicked

Asked

Viewed 1,350 times

0

I need that when a button is clicked, if the answer is correct the image (a bush) change (to a cow in front of the bush).

public class mudaSprite : MonoBehaviour {

public InputField dgt;
public Text txt;
public Sprite arbusto;
SpriteRenderer spriteRenderer = GetComponent<SpriteRenderer>();


public void setget(){

    if (dgt.text.ToLower().Equals("cinza")) {
        if (spriteRenderer.sprite == null) {
            spriteRenderer.sprite = Resources.Load<Sprite>("vacarbustoC");
        }
        ChangeTheDamnSprite ();

        txt.text = "";
    } 
    else {
        txt.text="Tente Novamente!";
    }
}

void ChangeTheDamnSprite(){
    if (spriteRenderer.sprite == arbusto) {
        spriteRenderer.sprite = Resources.Load<Sprite>("vacarbustoC");
    } else {
        spriteRenderer.sprite = arbusto;
    }
}

pleaaase!!

1 answer

1

I’ve already got!!!

I put the shrubs off the canvas, like Gameobject. So I put the above code associated with Gameobject and not the sprites.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.