Search Unity

How do I make a file selection menu like Zelda 64 & Mario 64?

Discussion in 'Scripting' started by davisdonarts, Jun 15, 2019.

  1. davisdonarts

    davisdonarts

    Joined:
    Dec 12, 2017
    Posts:
    27
    I tried finding this on youtube or google but can't find a Unity 5 tutorial?

    What I am trying to do is make a file selection menu with 3 files of starting the game. Each file has a separate playerpref values like most games would have? But I have no idea how to do this? It's like someone wants me to not add this feature to my games? o_O

    Maybe my own search filter is made this happen? :eek:

    Any idea's where I can find tutorials of file selection?
    If not? How do I code a file selection menu screen like Mario 64 and Zelda 64 for Unity?..

    Very much appreciated. :D

    Here is an example of what I am talking about.

    628465862_preview_ss+(2016-02-20+at+08.49.40).jpg maxresdefault.jpg
     
    Last edited: Jun 15, 2019
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    If you use PlayerPrefs to store the data, then add some checkboxes for "game files" and use check box names as key prefixes for player prefs, like a "FileA_PlayerLevel" instead of simple "PlayerLevel".
    And if you use file to save/load player progress, use
    Code (csharp):
    1. System.IO.Path.Combine(Application.dataPath, <checkbox_name>, <file_extension>)
    to load that file.
     
    davisdonarts likes this.
  3. davisdonarts

    davisdonarts

    Joined:
    Dec 12, 2017
    Posts:
    27
    I am a little bit confused? I have no idea where to put this in my code? But I did made 3 of the same scripts only named A, B, and C at the end of the name of the script. So when a player selects file A the player has a script named PlayerScriptA. Scripts B and C checkboxes are off for game file A.

    But when I clear playerpref keys it deletes all data even PlayerScriptB and C?
    What should I do? : /

    here's my code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine.UI;
    4. using UnityEngine;
    5.  
    6. public class PlayerScriptA : MonoBehaviour
    7. {
    8.     public Behaviour PlayerCountrollerScript;
    9.     public Behaviour PauseScript;
    10.  
    11.     public Text countCoinTextA;
    12.     public Text countLivesTextA;
    13.     public Text countTapesTextA;
    14.  
    15.     string coinsStringKeyA = "MyCoinsStringKeyA";
    16.     string livesStringKeyA = "MyLivesStringKeyA";
    17.     string tapesStringKeyA = "MyTapesStringKeyA";
    18.  
    19.  
    20.     public GameObject winScreen;
    21.     public GameObject gameOverMenu;
    22.  
    23.     public GameObject coinGOA;
    24.     public GameObject lifeUpGOA;
    25.     public GameObject tapeGOA;
    26.  
    27.     [SerializeField] public int coinsA;
    28.     [SerializeField] public int livesA;
    29.     [SerializeField] public int tapesA;
    30.  
    31.     private Rigidbody rb;
    32.  
    33.     // Start is called before the first frame update
    34.     void Start()
    35.     {
    36.         rb = GetComponent<Rigidbody>();
    37.  
    38.         coinsA = PlayerPrefs.GetInt("MyCoinsStringKeyA");
    39.         //PlayerPrefs.SetInt(coinsStringKey, coins);
    40.         //coins = PlayerPrefs.GetInt("coins", 0);
    41.         //coins = 0;
    42.         Debug.Log(PlayerPrefs.GetInt(coinsStringKeyA).ToString());
    43.  
    44.         livesA = PlayerPrefs.GetInt("MyLivesStringKeyA");
    45.         //PlayerPrefs.SetInt(livesStringKey, lives);
    46.         //lives = PlayerPrefs.GetInt("lives", 3);
    47.         //lives = 3;
    48.         Debug.Log(PlayerPrefs.GetInt(livesStringKeyA).ToString());
    49.  
    50.         tapesA = PlayerPrefs.GetInt("MyTapesStringKeyA");
    51.         //PlayerPrefs.SetInt(tapesStringKey, tapes);
    52.         //tapes = PlayerPrefs.GetInt("tapes", 0);
    53.         //tapes = 0;
    54.         Debug.Log(PlayerPrefs.GetInt(tapesStringKeyA).ToString());
    55.  
    56.         SetCountTextA();
    57.         SetLivesTextA();
    58.         SetTapesTextA();
    59.  
    60.         winScreen.SetActive(false);
    61.         gameOverMenu.SetActive(false);
    62.  
    63.         Time.timeScale = 1;
    64.     }
    65.  
    66.     // Update is called once per frame
    67.     void Update()
    68.     {
    69.         if (PlayerPrefs.GetInt("coinGOA", 0) == 1)
    70.         {
    71.             Destroy(coinGOA);
    72.         }
    73.         if (PlayerPrefs.GetInt("lifeUpGOA", 0) == 1)
    74.         {
    75.             Destroy(lifeUpGOA);
    76.         }
    77.         if (PlayerPrefs.GetInt("tapeGOA", 0) == 1)
    78.         {
    79.             Destroy(tapeGOA);
    80.         }
    81.         if (Input.GetKeyDown(KeyCode.Alpha1))
    82.         {
    83.             CleanDataA();
    84.             Debug.Log("Data cleared");
    85.          
    86.         }
    87.         if (Input.GetKeyDown(KeyCode.Alpha2))
    88.         {
    89.             DefaultDataA();
    90.             Debug.Log("Data reverted back to default");
    91.  
    92.         }
    93.     }
    94.  
    95.     private void OnTriggerEnter(Collider other)
    96.     {
    97.         if (other.gameObject.CompareTag("Pick Up"))
    98.         {
    99.             coinsA++;
    100.             PlayerPrefs.SetInt("MyCoinsStringKeyA",coinsA);
    101.             SetCountTextA();
    102.             //Time.timeScale = 1;
    103.             // Add sound for collecting coins
    104.             PlayerPrefs.SetInt("coinGOA", 1);
    105.             if (PlayerPrefs.GetInt("coinGOA", 0) == 1)
    106.             {
    107.                 Destroy(coinGOA);
    108.             }
    109.         }
    110.  
    111.         if (other.gameObject.CompareTag("LifeUp"))
    112.         {
    113.             livesA++;
    114.             PlayerPrefs.SetInt("MyLivesStringKeyA", livesA);
    115.             SetLivesTextA();
    116.             //Add the same life Up track
    117.             PlayerPrefs.SetInt("lifeUpGOA", 1);
    118.             if (PlayerPrefs.GetInt("lifeUpGOA", 0) == 1)
    119.             {
    120.                 Destroy(lifeUpGOA);
    121.             }
    122.         }
    123.  
    124.         if (other.gameObject.CompareTag("Tape"))
    125.         {
    126.             tapesA++;
    127.             PlayerPrefs.SetInt("MyTapesStringKeyA", tapesA);
    128.             winScreen.SetActive(true);
    129.             //Time.timeScale = 0;
    130.             SetTapesTextA();
    131.             //Add sound for collecting a tape.
    132.             PlayerPrefs.SetInt("tapeGOA", 1);
    133.             if (PlayerPrefs.GetInt("tapeGOA", 0) == 1)
    134.             {
    135.                 Destroy(tapeGOA);
    136.             }
    137.         }
    138.     }
    139.  
    140.     void SetCountTextA()
    141.     {
    142.         countCoinTextA.text = "X " + coinsA.ToString();
    143.         if (coinsA >= 100)
    144.         {
    145.             //Add life Up sound
    146.             livesA++;
    147.             PlayerPrefs.SetInt("MyLivesStringKeyA", livesA);
    148.             Time.timeScale = 1;
    149.         }
    150.     }
    151.     void SetLivesTextA()
    152.     {
    153.         countLivesTextA.text = "X " + livesA.ToString();
    154.         if (livesA <= 0)
    155.         {
    156.             // Add a game over music track
    157.             gameOverMenu.SetActive(true);
    158.         }
    159.     }
    160.     void SetTapesTextA()
    161.     {
    162.         countTapesTextA.text = "X " + tapesA.ToString();
    163.         if (tapesA >= 5)
    164.         {
    165.             winScreen.SetActive(true);
    166.         }
    167.     }
    168.     public void CleanDataA()
    169.     {
    170.         PlayerPrefs.DeleteKey(coinsStringKeyA);
    171.         PlayerPrefs.DeleteKey(livesStringKeyA);
    172.         PlayerPrefs.DeleteKey(tapesStringKeyA);
    173.     }
    174.     public void DefaultDataA()
    175.     {
    176.         //coins = PlayerPrefs.GetInt("coins", 1);
    177.         //coins = PlayerPrefs.SetInt("MyCoinsStringKey", 1);
    178.         PlayerPrefs.SetInt("MyCoinsStringKeyA", 0);
    179.         //lives = PlayerPrefs.GetInt("lives", 3);
    180.         //lives = PlayerPrefs.SetInt("MyLivesStringKey", 3);
    181.         PlayerPrefs.SetInt("MyLivesStringKeyA", 3);
    182.         //tapes = PlayerPrefs.GetInt("tapes", 1);
    183.         //tapes = PlayerPrefs.SetInt("MyTapesStringKey", 1);
    184.         PlayerPrefs.SetInt("MyTapesStringKeyA", 0);
    185.     }
    186. }
    187.  
    Any idea's
    most importantly, what's the search name for YouTube tutorials for "File selection menus in Unity"? I tried to search for an hour but can't find any? : /