Question by
kannan21 · Dec 28, 2015 at 09:06 AM ·
c#tutorialbestpracticesdesign-patterns
Tutorial level
This is my code for making a tutorial level which give instructions when the game is being played for the first time. It will show particular piece of instruction over the image which needs to be clicked to progress through the tutorial. Is there any better method to do this? Because this feels messy to me. i wrote a script for each scene.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class LoginTutorial : MonoBehaviour
{
public Image loginInstruction;
public BlinkComponent loginBlink;
void Start ()
{
if (PlayerPrefs.GetInt (Values.tutorialLogin)==0)
{
loginInstruction.enabled = true;
loginBlink.Activate();
}
}
void ButtonClickedCallback()
{
PlayerPrefs.SetInt (Values.tutorialLogin,1);
loginBlink.DeActivate();
}
[ContextMenu("Reset")]
void Reset()
{
PlayerPrefs.SetInt (Values.tutorialLogin,0);
}
}
The next one is for the menu scene.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class MenuTutorial : MonoBehaviour
{
public Image startgameInstruction;
public BlinkComponent startgameBlink;
public ButtonComponent startgameButton;
void Start ()
{
if (PlayerPrefs.GetInt (Values.tutorialMenu)==0)
{
Utility.DisableButtons ();
startgameInstruction.enabled = true;
startgameBlink.Activate ();
startgameButton.enabled = true;
}
}
void ButtonClickedCallback()
{
PlayerPrefs.SetInt (Values.tutorialMenu,1);
startgameBlink.DeActivate();
}
[ContextMenu("Reset")]
void Reset()
{
PlayerPrefs.SetInt (Values.tutorialMenu,0);
}
}
Comment
Answer by Gnorpelzwerg · Dec 28, 2015 at 09:49 AM
I think you could implement a base class/ interface and work with inheritance as long as the code for each tutorial has things in common. Then override in subclasses.
public class TutorialBase : MonoBehaviour {
}
public class TutorialSub : TutorialBase {
}