- Home /
switching scene, first one stops to work properly
Hi im new to unity (and programming!). i got a anoying problem and i would really need some help. When i first start the menu scene, everything works properly, then i go to another scene and work there, when i go back to start the first scene(menu) the gui button are invicible. This i know because i can still press it because i remember where it were
Those are the scripts script 1, used for the menu buttons: using UnityEngine; using System.Collections;
public class Start : MonoBehaviour {
bool showBox = false;
// Use this for initialization
void Start1 () {
}
// Update is called once per frame
void Update () {
}
void OnGUI(){
if (GUI.Button (new Rect (Screen.width / 2 - 50, Screen.height / 2 - 200, 200, 75), "<size=40>Start</size>")) {
showBox = true;
}
if (showBox) {
GUI.Box (new Rect (0, 0, 100, 25), "Loading...");
Application.LoadLevel ("något");
}
}
}
script 2, used for background image:
using UnityEngine;
using System.Collections;
public class BackgroundMeny : MonoBehaviour {
public Texture2D BackgroundMenu;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
GUI.DrawTexture(new Rect(0, 0, Screen.width , Screen.height ), BackgroundMenu, ScaleMode.StretchToFill, true, 10.0F);
}
}
so currently i have to make a new button script everytime for my menu to work. is this a bug or what? All help would be appreciated
Answer by eeveelution8 · Aug 25, 2014 at 01:24 AM
Boy I have the perfect script for you,
var ButtonID : int = 0;
// ID of 1 = Quit button.
// ID of 2 = Sceneloading button
// ID of 3 = Unhides an object
// ID of 4 = hides and object
// ID of 5 = turns off parent, while turning on target(useful for switching between tabs)
var ID2_Scene : String;
var ID_object : GameObject;
var ID5_target : GameObject;
function OnMouseDown(){
if(ButtonID == 1){
Application.Quit();
}
if(ButtonID == 2){
Application.LoadLevel(ID2_Scene);
}
if(ButtonID == 3){
ID_object.SetActive(true);
}
if(ButtonID == 4){
ID_object.SetActive(false);
}
if(ButtonID == 5){
gameObject.SetActive(false);
ID5_target.SetActive(true);
}
}
if it's a quit button, enter '1' into ButtonID, and leave the rest alone.
if the button loads a scene, enter '2' into ButtonID, and put the nameof your level into "ID2_Scene"
and so on and so on.
Wow , finaly an answer. Thanks! i think i solved this but i think this would work too and i'll probably replace it. :) I'm not really sure how to set your answer as "the answer" but thanks again!