I’m trying to move some pictures in an array forward with one UI Button then reverse with another button.I have it working somewhat, but when I reverse the numbers don’t work right…if going forward to the last one…if its the number 4 in the array…hitting the reverse button , should bring up picture number 4…instead it starts with 1,then 0, then -0…here’s my script
// cycle pictures forward and reverse
// using Unity 4.6
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Back_Forth : MonoBehaviour
{
public Sprite[] fish;
//public TextAsset[] myAssets;
public static int FWcount = 0;
public Image FishImage;
public Button forward;
public Button back;
//public Text myText;
void Start ()
{
FishImage.sprite= fish[FWcount];
//myText.text=""+myAssets[FWcount];
}
public void ForwardFish ()
{
if(forward)
{
FWcount = FWcount +1;
FishImage.sprite= fish[FWcount];
//myText.text=""+myAssets[FWcount];
if(FWcount>=2)
{ FWcount = 2; }
}
}
public void BackFish ()
{
if(back && FWcount>=0)
{
FishImage.sprite= fish[FWcount];
//myText.text=""+myAssets[FWcount];
FWcount = FWcount -1;
if(FWcount<0)
{ FWcount = 0; }
}
}
}