- Home /
How do I fix this issue with loading screen tips
I have been trying to make a script for loading scene tips in my game and I was wondering how to get the tips to reset. For example, I have 15 tips that play while the scene is loading, I want to know how to get the tip to go back to tip one. Im using different scenes for each of my tips which I know probably isnt the most efficient way but it seems to work. I am in unity version 2020.3.0f1 Here is the code I have at the moment using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;
public class next_tip : MonoBehaviour
{
public void PlayGame()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
here is a screenshot of some of the scenes I have for tips
Answer by Devster2020 · Jun 29, 2021 at 05:46 PM
Hello @ReferenceWolf Oh, the method you have chosen is one of the worst.
The best way to do this is to create a single "tip" scene and attach a script that has a list or array of tips, showing one every TOT seconds, and starting the loop over.
In this way:
public class TipsManager : MonoBehaviour {
[SerializeField] private Text tipsText;
[SerializeField] private string[] tips;
private int index;
void Start(){
this.index = 0;
this.ShowTip();
}
private void ShowTip(){
this.tipsText.Text = this.tips[this.index];
StartCoroutine(this.WaitAndLoadTip());
}
private IEnumerator WaitAndLoadTip(){
yield return new WaitForSeconds(3f);
this.index++;
if(this.index >= this.tips.Length)
this.index = 0;
this.ShowTip();
}
}
If you want to keep your method, and I don't recommend it, you have to create an index range between the first and last scene that shows the tips, and start the cycle again when you get to the last scene.
Hi there @Devster2020 I put the code into unity that you gave me and in line 9, unity seems to have a problem with the word "Text". I know that this shouldnt be the case and i've seen this used in other scripts. Any ideas?
hey there again, never $$anonymous$$d, sorry. I just forgot to put in "using UnityEngine.UI;"
Hey there @Devster2020 I'm really sorry to keep bothering you but now that I have added "using UnityEngine.UI" I get an error saying this "Assets\next_tip.cs(22,23): error CS1061: 'Text' does not contain a definition for 'Text' and no accessible extension method 'Text' accepting a first argument of type 'Text' could be found (are you missing a using directive or an assembly reference?)". I also have an error saying "Assets\next_tip.cs(23,9): error CS0103: The name 'StartCoroutine' does not exist in the current context". Is there any way you could help?
Hi @ReferenceWolf, and sorry but smartphone's keyboard change sometimes the case.. text must be all lowercase.
For StartCoroutine, you need to add "using System.Collections"
Hi there, @Devster2020, changing "Text" to all lowercases worked but "using System.Collections" was automatically at line 1 of my script when I made the script at the beginning. Is there any other fix? I'm very sorry for the inconveniences i've caused
Answer by Nistroy · Jun 29, 2021 at 06:26 PM
Hi @ReferenceWolf ! So if I understood correctly you want to load the scenes until the last one and then go back to the first. So there is a very easy way to do this is to use the "%" sign. This will fire the rest of the division. So for example you have 15 scenes. If you are at the 7th it will be: "7/15: R = 7". Then when you are at the 15th scene the rest of "15/15" will be 0. Sorry if I express myself badly I'm French haha ^^. Note: If you only want to make the scene count active in BuildSettings instead of sceneCount write sceneCountInBuildSettings
int _buildIndex = SceneManager.GetActiveScene().buildIndex + 1;
int sceneIndexToLoad = _buildIndex % SceneManager.sceneCount;
SceneManager.LoadScene(sceneIndexToLoad);
This code will not work if in the future he will add another scene like "itemShop".. so I think is not a good idea..
Your answer
Follow this Question
Related Questions
Loading Screen 2 Answers
Initial Web Player loading bar does't move when loading. 0 Answers
Unity WebGL loading screen customization 1 Answer
Loading screen bar not loading. 1 Answer