So I’m trying to make a simple tutorial for my “endless runner” type game that runs if the player high score is lower than 3, meaning that he is new to the game or doesn’t know how to play properly. What I want to achieve is something like this: The game freezes, display some text and an arrow pointing where the player has to click to advance through the game.
After that, the game unfreezes for a little and then it freezes again showing the next step of what he should do to procceed. It can go forever but Im thinking about 5 steps of freezing, changing the text and the position of the guiding arrow.
I came up with this but Im not sure how to implement the steps changing the text/arrow when the player clicks:
public class Tutorial : MonoBehaviour
{
public SaveState state;
public GameObject textContainer;
public Text tutorialTitle;
public Text tutorialText;
public Vector2 arrowPos;
void Start() {
if (state.highScore <= 2) {
StartCoroutine(RunTutorial());
}
if (state.highScore > 2) {
Destroy(tutorialText);
Destroy(gameObject);
}
}
IEnumerator RunTutorial() {
yield return new WaitForSeconds(1.5f);
Time.timeScale = 0;
textContainer.SetActive(true);
tutorialTitle.text = "Test tutorial Title";
tutorialText.text = "Test tutorial text";
}
public void Update() {
//if the player touches the screen it goes to the next step of the tutorial, doesnt matter if he touched the right place or is following it correctly.
if (Input.GetMouseButtonDown(0)) {
NextStep();
}
}
void NextStep() {
////Change description, title and arrow position for the next step in the tutorial and then
//make IEnumerator Runtutorial run again
}
}
As far as I know I think that it would work if I had an array list or an index foreach i in index or something like that,not sure, lists and index are kinda complicated for my newbie mind :s
New script closer to what I expected:
static List<string> titleStrings = new List<string>() { "Frame1", "Frame2", "Frame3", "Frame4", "Frame5", };
static List<string> textStrings = new List<string>() { "Message1", "Message2", "Message3", "Message4", "Message5", };
public static bool lastFinished;
void Start() {
//Check List make sure its safe to continue
if(Equals(titleStrings,null) && Equals(textStrings,null)){
//Set Defaults.
titleStrings = new List<string>() { "Frame1", "Frame2", "Frame3", "Frame4", "Frame5", };
textStrings = new List<string>() { "Message1", "Message2", "Message3", "Message4", "Message5", };
}else{
if (SaveManager.Instance.state.highScore <= 3) {//less then or equal
selection = 0;
StartCoroutine(RunTutorial(selection));
tutorialTitle.text = titleStrings[selection];
} else {//otherwise
//You don't wanna remove or else you may get a null reff error.
}
}
}
void Update(){
if(!lastFinished){
Time.timeScale = 0;
}else{
Time.timeScale = 1;
}
print(lastFinished);
//if the player touches the screen it goes to the next step of the tutorial,
//doesnt matter if he touched the right place or is following it correctly.
if (Input.GetMouseButtonDown(0) && lastFinished) {
StartCoroutine(NextStep());
}
//Check List make sure its save to continue
if(Equals(SaveManager.Instance.state.highScore < 3)){
return;// Doesn't do anything if Player score is above 3
}else{
if (SaveManager.Instance.state.highScore <= 3 && selection <= 5 && lastFinished) {//less then or equal
StartCoroutine(RunTutorial(selection));
tutorialTitle.text=titleStrings[selection];
} else {//otherwise
//You don't wanna remove or else you may get a null reff error.
}
}
}
IEnumerator RunTutorial(int currentTutSelection) {
if(Equals(currentTutSelection,selection)){
print("TEST");
lastFinished = false;
yield return new WaitForSeconds(0.5f);
textContainer.SetActive(true);
tutorialTitle.text = titleStrings[currentTutSelection];
tutorialText.text = textStrings[currentTutSelection];
lastFinished = true;
} else {
yield return new WaitForSeconds(0.01f);//To Satisfy method
}
}
IEnumerator NextStep() {
textContainer.SetActive(false);
yield return new WaitForSeconds(0.5f);
ChangeNext();
}
//public change next button
public void ChangeNext(){
selection++;
}
//override to skip all or to specific
public void ChangeLast(int lastSelectionValue){
selection = lastSelectionValue;
}
//enable something
public void ActivateGameObject (GameObject go)
{
go.SetActive (true);
}
//disable something
public void DeactivateGameObject (GameObject go)
{
go.SetActive (false);
}
}