I try to deactivate the next button on the last page of the tutorial (4) and activate it when I am on previous pages(0-3).
I would also like to deactivate the previous button when I am on the first page of the tutorial (0) and activate it when I am on the next pages of the tutorial (1-4).
Unfortunately, I don’t know why, but I can’t do it. The buttons disappear once, appear once. In turn, once it disappears, it doesn’t appear. Can anyone improve my code and explain what I did wrong?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using UnityEngine.SceneManagement;
public class MenuPanel : MonoBehaviour
{
public GameObject[] tutorialPage;
[SerializeField] GameObject buttonLeft;
[SerializeField] GameObject buttonRight;
int currentIndex = 0;
public int CurrentIndex
{
get
{
return currentIndex;
}
set
{
if (tutorialPage[currentIndex] != null)
{
//set the current active object to inactive, before replacing it
GameObject aktivesObj = tutorialPage[currentIndex];
aktivesObj.SetActive(false);
}
if (value < 0)
currentIndex = tutorialPage.Length - 1;
else if (value > tutorialPage.Length - 1)
currentIndex = 0;
else
currentIndex = value;
if (tutorialPage[currentIndex] != null)
{
GameObject aktivesObj = tutorialPage[currentIndex];
aktivesObj.SetActive(true);
}
}
}
public void Next(int direction)
{
if (direction >= 1)
CurrentIndex++;
if (currentIndex >= 4)
{
buttonRight.SetActive(false);
}
if (currentIndex <= 3)
{
buttonRight.SetActive(true);
}
}
public void Previous(int direction)
{
if (direction == 0)
CurrentIndex--;
if (currentIndex ==0)
{
buttonLeft.SetActive(false);
}
if (currentIndex >= 1)
{
buttonLeft.SetActive(true);
}
}
public void OnClickTutorialPanel()
{
currentIndex = 0;
buttonRight.SetActive(true);
buttonLeft.SetActive(false);
tutorialPage[0].SetActive(true);
Tutorial.SetActive(true);
}
public void OnClickBackToSettings(){
tutorialPage[currentIndex].SetActive(false);
Tutorial.SetActive(false);
}
}