- Home /
Menu won't hide when loading different scene
Okay, so I've been searching for about an hour now, and I can't find a solution at all. I started this project earlier today and it's my first project using Unity. I followed the very first tutorial on the site "Roll a Ball". I have then been using it as a baseline to expand it into something different (eventually). I've been playing around with little bits of code here and there, and adding little bits to get a grip for it all.
However now I am stuck. I have a menu page which allows me to start game, load game (which in itself gives a warning because that feature isn't implemented yet) and a quit game button.
It looks like this; http://i.gyazo.com/524684969a803a4a7c89a9e01a3ea45d.png
The problem I am having is this: http://i.gyazo.com/8d95ac9db707b40e38b2d85c2ecc400a.png
Here is the code below.
Menu.cs
using UnityEngine;
using System.Collections;
using CorruptedSmileStudio.MessageBox;
public class Menu : MonoBehaviour
{
void OnGUI ()
{
// Make a background box
GUI.Box (new Rect (10, 10, 100, 120), "Main Menu");
// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
if (GUI.Button (new Rect (20, 40, 80, 20), "Start Game"))
{
Application.LoadLevel (1);
}
// second button
if (GUI.Button (new Rect (20, 70, 80, 20), "Load Game"))
{
MessageBox.Show (null, "I'm sorry, but the load game feature is not current avalible in this build.", "Load Game Feature", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
// Make the third button.
if (GUI.Button (new Rect (20, 100, 80, 20), "Quit"))
{
Application.Quit ();
}
}
}
PlayerController.cs
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed;
public Text winText;
private Rigidbody rb;
private int count;
private float timer;
void Start()
{
rb = GetComponent<Rigidbody> ();
count = 0;
timer = 0.0f;
}
void FixedUpdate()
{
if (count < 11)
{
timer += Time.deltaTime;
}
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
CheckIfWon ();
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Pick Up"))
{
other.gameObject.SetActive (false);
count = count + 1;
}
}
void CheckIfWon ()
{
if (count >= 11)
{
Application.LoadLevel(0);
}
}
void OnGUI()
{
GUI.Box(new Rect(5, 0, 100, 20), "Cubes: " + count.ToString("0")); // score
GUI.Box(new Rect(5, 20, 100, 20), "Time: " + timer.ToString("0")); // timer
}
}
Thanks for any, and all helpful responses. :)
you sure that on the new scene you didn't add the menu as a component to something?
Answer by Burridge · May 03, 2015 at 08:23 PM
Wow, it took ages for this post to appear on the site. I have fixed it since.
http://i.gyazo.com/56c0f220d4e60e493f028d261ad5d932.png
I had to uncheck the "Dont Destroy function" and it now works as I want it to :)
Your answer
Follow this Question
Related Questions
switching scene, first one stops to work properly 1 Answer
Character spawn menu bug 0 Answers
Editor menus are invisible 1 Answer
how to make it die and make it permanent(true)? 1 Answer
Button doesn't work after build 1 Answer