Expanding onto the 2D RougeLike Game adding a main menu (URGENT! help required please)
PLEASE HELP URGENTLY! I have posted three discussion board postings' and i have sent an E-mail and i really need some help please, i have included my original message. I have attempted the Main Menu tutorial however, it bugs out it allows me to start the game and it works until i transition to the next level. Then it goes back to the main menu then i click play again, and it jumps two levels ahead in the game.
Hello any and all,
I am attempting to expand the Rougelike 2D game from the Unity tutorial. What i want to do is simple (in theory) I would like to add a basic menu with a Play, Leader board and Exit buttons', When Play has been clocked the game runs and upon death, another option pops up to return to the min menu or exit the game after the player entered their the initials for their score to be added to the scoreboard. When the returns to the Main menu they can play again by pressing play, the only way they can exit the game is by pressing the exit button on the main menu or upon death pressing exit.
Now, i have found a tutorial for a main menu but it is not working (Tutorial URL http://pixelnest.io/tutorials/2d-game-unity/menus/ ) The part to at the MenuScript.StartGame() to then add the StartGame() function does not work in the way it was shown in the tutorial in my version of Unity version 5.6.0f3 Personal 64 But Windows edition.
I have also found a leaderboard tutoral at (URL https://docs.gamesparks.net/tutorials/unity-tutorial-creating-leaderboard-prefabs-posting-scores ) I have not started this one yet for, i am still creating the menu.
So, after all of that this is the issue(s) The menu button is not working and due to the fact this is for different projects i know it will interfere with the games tutorial built loops'.
I just want to make a working menu, arcade-style leader-board and options after death.
Thank you to any and all help
P.S. Please be kind i am still new to game development.
Sincerely,
R.E.D.
Hello all, long story short i have expanded the RougeLike 2D game from Unity technologies https://unity3d.com/learn/tutorials/projects/2d-roguelike-tutorial
The issue is i have added my own main menu with a play and exit button. Now, the main issue is after i click play, it loads the Scene from the int index i have defined then when i stand on the exit tile to go to the next level, it returns to the main menu. Then i click play again it then re-loads the first level as a blank black screen, and if i once again walk over the exit tile the game bugs out abysmally. I believe it has something to do with the GameManager script with its code to repeat the level which is literally "level++" code.
PLEASE, any help will be greatly appreciated. I have also included the GameManager script code for reference and the play button as well.
GameManager Script
private Text levelText; //Text to display current level number.
private GameObject levelImage; //Image to block out level as levels are being set up, background for levelText.
private BoardManager boardScript; //Store a reference to our BoardManager which will set up the level.
private int level = 1; //Current level number, expressed in game as "Day 1".
private List<Enemy> enemies; //List of all Enemy units, used to issue them move commands.
private bool enemiesMoving; //Boolean to check if enemies are moving.
private bool doingSetup = true; //Boolean to check if we're setting up board, prevent Player from moving during setup.
//Awake is always called before any Start functions
void Awake()
{
//Check if instance already exists
if (instance == null)
//if not, set instance to this
instance = this;
//If instance already exists and it's not this:
else if (instance != this)
//Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
Destroy(gameObject);
//Sets this to not be destroyed when reloading scene
DontDestroyOnLoad(gameObject);
//Assign enemies to a new List of Enemy objects.
enemies = new List<Enemy>();
//Get a component reference to the attached BoardManager script
boardScript = GetComponent<BoardManager>();
//Call the InitGame function to initialize the first level
InitGame();
}
void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode)
{
++level;
InitGame();
}
void OnEnable()
{
SceneManager.sceneLoaded += OnLevelFinishedLoading;
}
void OnDisable()
{
SceneManager.sceneLoaded -= OnLevelFinishedLoading;
}
//Initializes the game for each level.
void InitGame()
{
//While doingSetup is true the player can't move, prevent player from moving while title card is up.
doingSetup = true;
//Get a reference to our image LevelImage by finding it by name.
levelImage = GameObject.Find("LevelImage");
//Get a reference to our text LevelText's text component by finding it by name and calling GetComponent.
levelText = GameObject.Find("LevelText").GetComponent<Text>();
//Set the text of levelText to the string "Day" and append the current level number.
levelText.text = "Day " + level;
//Set levelImage to active blocking player's view of the game board during setup.
levelImage.SetActive(true);
//Call the HideLevelImage function with a delay in seconds of levelStartDelay.
Invoke("HideLevelImage", levelStartDelay);
//Clear any Enemy objects in our List to prepare for next level.
enemies.Clear();
//Call the SetupScene function of the BoardManager script, pass it current level number.
boardScript.SetupScene(level);
}
//Hides black image used between levels
void HideLevelImage()
{
//Disable the levelImage gameObject.
levelImage.SetActive(false);
//Set doingSetup to false allowing player to move again.
doingSetup = false;
}
//Update is called every frame.
void Update()
{
//Check that playersTurn or enemiesMoving or doingSetup are not currently true.
if (playersTurn || enemiesMoving || doingSetup)
//If any of these are true, return and do not start MoveEnemies.
return;
//Start moving enemies.
StartCoroutine(MoveEnemies());
}
//Call this to add the passed in Enemy to the List of Enemy objects.
public void AddEnemyToList(Enemy script)
{
//Add Enemy to List enemies.
enemies.Add(script);
}
//GameOver is called when the player reaches 0 food points
public void GameOver()
{
//Set levelText to display number of levels passed and game over message
levelText.text = "After " + level + " days, you starved.";
//Enable black background image gameObject.
levelImage.SetActive(true);
//Disable this GameManager.
enabled = false;
}
//Coroutine to move enemies in sequence.
IEnumerator MoveEnemies()
{
//While enemiesMoving is true player is unable to move.
enemiesMoving = true;
//Wait for turnDelay seconds, defaults to .1 (100 ms).
yield return new WaitForSeconds(turnDelay);
//If there are no enemies spawned (IE in first level):
if (enemies.Count == 0)
{
//Wait for turnDelay seconds between moves, replaces delay caused by enemies moving when there are none.
yield return new WaitForSeconds(turnDelay);
}
//Loop through List of Enemy objects.
for (int i = 0; i < enemies.Count; i++)
{
//Call the MoveEnemy function of Enemy at index i in the enemies List.
enemies[i].MoveEnemy();
//Wait for Enemy's moveTime before moving next Enemy,
yield return new WaitForSeconds(enemies[i].moveTime);
}
//Once Enemies are done moving, set playersTurn to true so player can move.
playersTurn = true;
//Enemies are done moving, set enemiesMoving to false.
enemiesMoving = false;
}
}
Play button script
public void LoadByIndex(int sceneIndex)
{
SceneManager.LoadScene(sceneIndex);
}
}
Hi, I have similar issue after adding main menu. After steping on exit tile its adding two days ins$$anonymous$$d of one and zeroes my food. It is because "OnLevelWasLoaded" is being called twice. Ive added simple if statement: if (index == 2) //2 is the index of my game scene in build manager Now its only adding one day but it stills zeroes my food. Do you have any solution mate? Your question has more then a year so I hope you found a solution ^^
Answer by Furjoza · Mar 18, 2018 at 08:19 PM
Okay I got it mate. If you want to add new scene as your main menu you need to change the code of OnLevelWasLoaded and Awake methods from game manager. In the first one you want to add if statement like this:
private void OnLevelWasLoaded(int index)
{
if (index == 2)
{
level++;
InitGame();
}
}
where "2" is my index number of the game scene in build settings and also you need to remove "InitGame()" method from Awake() method.
Regards, Jakub
To get this to work, I had to add
Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene().buildIndex);
Ins$$anonymous$$d of
Invoke("Restart", restartLevelDelay);
In Player.cs for the OnTriggerEnter2D method for when the player collides with the exit.
Just adding this to save other people a bit of time!
Your answer
Follow this Question
Related Questions
Issue with loading scenes with buttons 1 Answer
Pause button not working correctly 1 Answer
Photon Player And Weapon View Error 0 Answers