I have a Left Button and a Right Button, when the player presses the Right Button the default tip becomes disabled and the next tip becomes enabled. There are 12 tips.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Tips : MonoBehaviour
{
public GameObject tipsManager;
public GameObject tips;
public Text tip1;
public Text tip2;
public Text tip3; //...etc
private void Start()
{
tipsManager.SetActive(true);
}
public void DisableTips() //Hitting the X button disables the Tips Manager.
{
tipsManager.SetActive(false);
}
public void NextTip() //When the > button is presssed.
{
}
public void PreviousTip() //When the < button is pressed.
{
}
}
I think I need to use a List? I’m not sure… I would really appreciate some direction.
You should be using an array or a list, yes. If you ever find yourself “numbering” your variables like this, an array or list would be a better option.
Oh, ok! Whats the best way to do that in this case? I’m sorry, it appears I have missed some fundamentals… I took a couple weeks off and I forget what I’m doing. LOL
Yes – put the hints into a List or an Array and use an integer to know which one you’re on. There are lots of places to look for this – faster than waiting for someone to retype them here. “Unity make list in Inspector” “C# list of strings”, “C# how to print item in list” and so on. It’s pretty generic programming. Once you have the hint in a string, “Unity display string” would help.
Nice! That solves the List issue, I’m sorry but I forget how to cycle through these. I think this would be an ++ for Next Tip and a – for Previous tip. Will need to SetActive the previous tip to false and SetActive the next tip to true, but… Couldn’t find any good results in google for this particular function.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Tips : MonoBehaviour
{
public GameObject tipsManager;
public List<GameObject> tips = new List<GameObject>();
private void Start()
{
tipsManager.SetActive(true);
}
public void DisableTips() //Hitting the X button disables the Tips Manager.
{
tipsManager.SetActive(false);
}
public void NextTip() //When the > button is presssed.
{
}
public void PreviousTip() //When the < button is pressed.
{
}
}
You would need a variable like int currentTipIndex and yes increment it to go to the next tip, decrement to go to the previous. Don’t forget to handle the edge cases when you’re at the beginning/end of the list.