Question by
StardustLegend · Sep 22, 2016 at 08:06 PM ·
scripting problemscripting beginnerscriptingbasicsscriptingproblem
Help with Changing the Sprite image in the Script
I am still somewhat new to coding, and i need help changing a sprite of an image. there are two sprites, 1 shows the image i want to project, and the other is a button that changes the image of the first sprite. only the second sprite has the script, but i'm not sure where i went wrong. here is the script:
using UnityEngine; using System.Collections;
public class ChangeImage : MonoBehaviour {
public GameObject Scene;
public Sprite IMG_0078;
public Sprite IMG_0079;
public Sprite IMG_0080;
public Sprite IMG_0094;
// Use this for initialization
void Start () {
Scene = GetComponent<SpriteRenderer> ();
}
void OnMouseDown()
{
SetSprite ();
}
// Update is called once per frame
void SetSprite ()
{
if (SpriteRenderer.Sprite == IMG_0078)
{
SpriteRenderer.Sprite = IMG_0079;
}
if (SpriteRenderer.Sprite == IMG_0079)
{
SpriteRenderer.Sprite = IMG_0080;
}
if (SpriteRenderer.Sprite == IMG_0080)
{
SpriteRenderer.Sprite = IMG_0094;
}
} void Update () {
}
}
Comment