- Home /
Toggle through sprites on UI button press
Hi,
I've been fiddling around with this issue for a while now, I am having a problem toggling through four sprites when pushing a 'next' button. I can't change the scene because there is a video playing next to the text. I'm not seeing any errors thrown and I've filtered through tons of forums and tutorials, but I am still stuck. If anyone can point me in the direction of a tutorial or see anything wrong with the code, I would be very grateful.
Thank you so much in advance, the forums have really helped me learn a lot about this program.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ButtonToggle : MonoBehaviour {
public Sprite PanelOne;
public Sprite PanelTwo;
public Sprite PanelThree;
public Sprite PanelFour;
private SpriteRenderer spriteRender;
void Start () {
spriteRender = GetComponent<SpriteRenderer> ();
/*if (spriteRender.sprite == null) {
spriteRender.sprite = PanelOne;
}*/
}
public void changeSprite () {
if (spriteRender.sprite == PanelOne) {
spriteRender.sprite = PanelTwo;
} else if (spriteRender.sprite == PanelTwo) {
spriteRender.sprite = PanelThree;
} else if (spriteRender.sprite == PanelThree) {
spriteRender.sprite = PanelFour;
}
else {
spriteRender.sprite = PanelFour;
}
}
}
Comment