Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Marooned9 · Mar 26, 2019 at 11:37 PM · 2droguelike

Adding Main Menu to Unity's official Roguelike tutorial

I've been trying to add a main menu to the game from unity's Roguelike tutorial but every time I complete a level the menu opens again. What should I do to fix this?

GameManager script

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 using UnityEngine.UI;
 
 public class GameManager : MonoBehaviour
 {
     public static GameManager instance = null;
 
     public BoardManager boardScript;
     public int playerFoodPoints = 100;
     [HideInInspector] public bool playersTurn = true;
     public float turnDelay = .1f;
     public float levelStartDelay = 2f;
 
     private int level = 0;
     private List<Enemy> enemies;
     private bool enemiesMoving;
     private Text levelText;
     private GameObject levelImage;
     private bool doingSetup;
 
     void Awake()
     {
         if (instance == null) {
             instance = this;
         } else if (instance != this) {
             Destroy(gameObject);
         }
 
         DontDestroyOnLoad(gameObject);
 
         enemies = new List<Enemy>();
 
         boardScript = GetComponent<BoardManager>();
         
     }
 
     void InitGame()
     {
         doingSetup = true;
 
         levelImage = GameObject.Find("LevelImage");
         levelText = GameObject.Find("LevelText").GetComponent<Text>();
         levelText.text = "Dia " + NumberToWords(level);
         levelImage.SetActive(true);
 
         Invoke("HideLevelImage", levelStartDelay);
 
         enemies.Clear();
 
         boardScript.SetupScene(level);
     }
 
     private void HideLevelImage()
     {
         levelImage.SetActive(false);
         doingSetup = false;
     }
 
     void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode)
     {
             level++;
             InitGame();
     }
 
     void OnEnable()
     {
         SceneManager.sceneLoaded += OnLevelFinishedLoading;
     }
 
     void OnDisable()
     {
         SceneManager.sceneLoaded -= OnLevelFinishedLoading;
     }
 
     void Update()
     {
         if (playersTurn || enemiesMoving || doingSetup) {
             return;
         }
 
         StartCoroutine(MoveEnemies());
     }
 
     public void AddEnemyToList(Enemy script)
     {
         enemies.Add(script);
     }
 
     public void GameOver()
     {
         levelText.text = "Sobreviveu " + NumberToWords(level).ToLower() + " " + ((level <= 1) ? "dia" : "dias");
         levelImage.SetActive(true);
 
         enabled = false;
     }
 
     IEnumerator MoveEnemies()
     {
         enemiesMoving = true;
 
         yield return new WaitForSeconds(turnDelay);
 
         if (enemies.Count == 0) {
             yield return new WaitForSeconds(turnDelay);
         }
 
         for (int i = 0; i < enemies.Count; i++)
         {
             enemies[i].MoveEnemy();
 
             yield return new WaitForSeconds(enemies[i].moveTime);
         }
             
         enemiesMoving = false;
 
         playersTurn = true;
     }
 
     private static string NumberToWords(int number)
     {
         if (number == 0)
             return "Zero";
 
         if (number < 0)
             return "Menos " + NumberToWords(Math.Abs(number));
 
         string words = "";
 
         if ((number / 1000000) > 0)
         {
             words += NumberToWords(number / 1000000) + " Milhão ";
             number %= 1000000;
         }
 
         if ((number / 1000) > 0)
         {
             words += NumberToWords(number / 1000) + " Milhar ";
             number %= 1000;
         }
 
         if ((number / 100) > 0)
         {
             words += NumberToWords(number / 100) + " Centena ";
             number %= 100;
         }
 
         if (number > 0)
         {
             if (words != "")
                 words += "e ";
 
             var unitsMap = new[] { "Zero", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19" };
             var tensMap = new[] { "Zero", "10", "20", "30", "40", "50", "60", "70", "80", "90" };
 
             if (number < 20)
                 words += unitsMap[number];
             else
             {
                 words += tensMap[number / 10];
                 if ((number % 10) > 0)
                     words += "-" + unitsMap[number % 10];
             }
         }
 
         return words;
     }
 }
 

Menu script

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class MainMenu : MonoBehaviour {
 
     public void PlayGame ()
     {
         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
     }
 
     public void QuitGame ()
     {
         Debug.Log("SAIR!");
         Application.Quit();
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

201 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Modifying the 2D Roguelike Player Script to Expect Other Objects 0 Answers

Texture grid displayed oddly when width =/= height 1 Answer

2D Animation does not start 1 Answer

How to have graphic continuity in my chuncks ?(2d procedural / sprites) 1 Answer

Unity2D Pixels deforming when moving 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges