I have set up a script to set game objects as active/inactive depending on a particular number representing the index of a gameObject array. As you can see the image below. I have two buttons as shown on the page, a backward button and a forward button. I have attached event trigger components to each of the buttons so as to turn pages forward / backward depending on which button I click
The forward button works but this is not the case with the backward button. The function is not even being called. In fact only this sprite which on being clicked does not call the function assigned to it.
More details on the backbutton :
Here is the script for the MonsterRosterManager.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MonsterRosterManager : MonoBehaviour
{
int MonsterPageNo;
public GameObject[] MonsterPages;
void Start()
{
MonsterPageNo = 0;
}
void Update()
{
switch (MonsterPageNo)
{
case 0:
MonsterPages[0].SetActive(true);
MonsterPages[1].SetActive(false);
MonsterPages[2].SetActive(false);
break;
case 1:
MonsterPages[0].SetActive(false);
MonsterPages[1].SetActive(true);
MonsterPages[2].SetActive(false);
break;
case 2:
MonsterPages[0].SetActive(false);
MonsterPages[1].SetActive(false);
MonsterPages[2].SetActive(true);
break;
}
}
public void PrevMonsterPage()
{
Debug.Log ("Monster Page No to decrement: "+MonsterPageNo);
MonsterPageNo -= 1;
if (MonsterPageNo == -1)
MonsterPageNo = 0;
}
public void NextMonsterPage()
{
Debug.Log ("Monster Page No to increment: "+MonsterPageNo);
MonsterPageNo += 1;
if (MonsterPageNo == MonsterPages.Length)
MonsterPageNo = MonsterPages.Length - 1;
}
}
Furthermore, the logs below show that the NextMonsterPage()
function is called on clicking the forward button, but no calls to the PrevMonsterPage()
are being registered.
What am I overlooking here?