[Edited; thank you YBtheS!]
I have a scriptable object called a “page” that contains both text and an array of “next pages.” I’m trying to get this script so that when I click a button it loads the corresponding page in the array, and I can’t seem to get it to display. Here’s what happens when I click the button:
Click 1
Click 2
So apparently the next page is loaded but not displayed? If anyone can help me figure out what to do it would be amazing
public class UserInputHandler : MonoBehaviour
{
AdventureGame adventureGame;
[SerializeField] Button a;
[SerializeField] Button b;
[SerializeField] Button c;
Page currentPage;
Page[] nextPages;
bool pageNamed;
//Start Menu
public void NewStoryButton()
{
//prompt for story name
//create folder for story pages titled with the story name
//load new page in editor
}
//Editor
void Start ()
{
adventureGame = FindObjectOfType<AdventureGame>();
}
private void PageButtons()
{
Page p = adventureGame.GetCurrentPage();
nextPages = new Page[p.GetNextPages().Length];
Debug.Log(nextPages.Length);
nextPages = p.GetNextPages();
}
//A: if adventureGame currentPage has nextPages[0], load nextPages[0], else create new page
public void A_Button()
{
PageButtons();
//if currentPage has nextPage[0] = true, load nextPages[0]
if (nextPages[0] == null)
{
adventureGame.CreateNewPage();
Debug.Log("New page created");
}
else
{ //these next two lines are what I've tried so far
adventureGame.SetCurrentPage(nextPages[0]);
adventureGame.ManagePage();
Debug.Log(nextPages[0]);
}
}
//B: if currentPage has nextPages[1], return true; else false
public void B_Button()
{
PageButtons();
adventureGame.ManagePage();
// if currentPage has nextPage[1] = true, load nextPages[0]
if (nextPages[1] == null)
{
adventureGame.CreateNewPage();
}
else
{
}
}
//C: if currentPage has nextPages[2], return true; else false
public void C_Button()
{
PageButtons();
adventureGame.ManagePage();
if (nextPages[2] == null)
{
}
else
{
Debug.Log(nextPages[2]);
}
}
private void DisableButtons()
{
PageButtons();
//if nextPages[] has no elements, disable B & C
if (nextPages[0] == null && nextPages[1] == null && nextPages[2] == null)
{
a.interactable = true;
b.interactable = false;
c.interactable = false;
}
//if nextPages[] does not have elements 0 & 1, disable C
else if (nextPages[1] == null && nextPages[2] == null)
{
a.interactable = true;
b.interactable = true;
c.interactable = false;
}
//if nextPages[] has all 3 elements, buttons enabled
else
{
a.interactable = true;
b.interactable = true;
c.interactable = true;
}
}
private void Update()
{
DisableButtons();
}
}
public class AdventureGame : MonoBehaviour
{
[SerializeField] public TextMeshProUGUI storyText;
[SerializeField] Page newPage;
public Page currentPage;
Page[] nextPages;
// Use this for initialization
void Start()
{
CreateNewPage();
}
public void CreateNewPage()
{
currentPage = newPage;
GetPageText();
}
public Page GetCurrentPage()
{
return currentPage;
}
public void SetCurrentPage(Page page)
{
currentPage = page;
}
public void ManagePage()
{
nextPages = currentPage.GetNextPages();
GetPageText();
}
private void GetPageText()
{
storyText.text = currentPage.GetPageText();
}
}