- Home /
How to make my tutorial appear only once?
I don't think it's possible with unity, but I'd like my little tutorial to show once on the first play, & never show again when the player plays the game for the second time & so on.
Saying "I don't think it's possible with Unity" is essentially saying "I have a problem that Unity has never considered and that the entire C# language cannot solve". It's possible and it's simple to implement 100 different ways, but the Unity-specific solution might be to just use PlayerPrefs.
https://docs.unity3d.com/ScriptReference/PlayerPrefs.html
If(PlayerPrefs.GetInt("FirstTime") == 0)
{
//Load tutorial
}
else
{
//load something different
}
Just set do PlayerPrefs.SetInt("FirstTime") == 1 when the player finishes the tutroial.
Answer by RyanAtEvno · Mar 30, 2018 at 08:52 PM
Basically in start function PlayerPref.SetInt ("TutorialHasPlayed", 0);
Then for your tutorial start put if (PlayerPref.GetInt ("TutorialHasPlayed", 0) <= 0) {//--start tutorial--//; PlayerPref.SetInt ("TutorialHasPlayed", 1); }
. This will set the playerpref int with 0 as false and 1 as true. Once the tutorial plays It will set the int to 1 as true and it will no longer play on that device.
Thank you! This is sure to help my game appear better, as well as make a somewhat advanced tutorial system.
Answer by Razputin · Mar 30, 2018 at 11:05 PM
If(PlayerPrefs.GetInt("FirstTime") == 0)
{
//Load tutorial
}
else
{
//load something different
}
Just do PlayerPrefs.SetInt("FirstTime",1) when the player finishes the tutorial.
Answer by Rygaran · Mar 30, 2018 at 08:19 PM
you can make your tutorials dependant on a bool, that after first play gets set to false. you could store it in playerprefs, and even make it a setting in a menu.
Answer by A3miz · Feb 22, 2021 at 01:49 PM
using System;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameLaunchCounter : MonoBehaviour
{
string SessionNumber = PlayerPrefs.GetString("unity.player_session_count");
private void Start()
{
if (SessionNumber == "0")
{
SceneManager.LoadScene("Tutorial");
else
{
SceneManager.LoadScene("SomethingElse")
}
}
}
}
Here's a better ready script if needed. No errors expected.
using System; using UnityEngine; using UnityEngine.SceneManagement; public class TutorialScript : MonoBehaviour { private void Start() { string SessionNumber = PlayerPrefs.GetString("unity.player_session_count"); if (SessionNumber == "0") { SceneManager.LoadScene("Tutorial"); } else { SceneManager.LoadScene("MainMenu"); } } }
I don't think this could work, because the player can enter the game and exit before completing the tutorial, and that would make the unity.player_session_count > 0 but the player didn't do the tutorial
Your answer
Follow this Question
Related Questions
how do i make a level map like super mario 3 1 Answer
Side battle tutorial using 3d objects 0 Answers
Enemy AI script trouble(Js to c#) 3 Answers
Stealth project: lightmapping artifacts 1 Answer
Why is the boundary not working? 1 Answer