Advertisement
johnnygoodguy2000

MainMenu.cs

May 12th, 2024 (edited)
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5.  
  6. public class MainMenu : MonoBehaviour
  7. {
  8.  public string startLevel;// Updated to use SceneManager
  9.  public string levelSelect; // Updated to use SceneManager
  10.  public int playerHealth;// Set the player's health to the playerHealth variable
  11.  
  12.  
  13.  public int playerLives;
  14.  public void NewGame()
  15.  {
  16.     // Application.LoadLevel(startLevel);
  17.     SceneManager.LoadScene(startLevel);
  18.  
  19.     PlayerPrefs.SetInt("PlayerCurrentLives", playerLives);
  20.  
  21.     PlayerPrefs.SetInt("PlayerCurrentScore", 0);
  22.  
  23.     PlayerPrefs.SetInt("PlayerCurrentHealth", playerHealth); // Set the player's health to the playerHealth variable
  24.     PlayerPrefs.SetInt("PlayerMaxHealth", playerHealth);// Set the player's health to the playerHealth variable
  25.  
  26.  
  27.  
  28.  }
  29.  
  30.  public void LevelSelect()
  31.  {
  32.    PlayerPrefs.SetInt("PlayerCurrentLives", playerLives);// Set the player's lives in the PlayerPrefs
  33.  
  34.    PlayerPrefs.SetInt("PlayerCurrentScore", 0);// Set the player's score in the PlayerPrefs
  35.  
  36.    PlayerPrefs.SetInt("PlayerCurrentHealth", playerHealth); // Set the player's health to the playerHealth variable
  37.    PlayerPrefs.SetInt("PlayerMaxHealth", playerHealth);// Set the player's health to the playerHealth variable
  38.  
  39.  
  40.     // Application.LoadLevel(levelSelect);
  41.     SceneManager.LoadScene(levelSelect);
  42.  
  43.  }
  44.  
  45.  public void QuitGame()
  46.  {
  47.      Application.Quit();
  48.  }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement