- Home /
Question by
davidflynn2 · Jul 10, 2013 at 09:36 PM ·
c#guisaving
Working With GUI
I am working on a GUI for saving and loading my game the problem is I don't want the GUI to show up unless you press the "P" button but when I put this part in it no longer works. It don't throw no errors but the GUI wont popup.
Here is my code:
using UnityEngine;
using System.Collections;
public class GrassPause : MonoBehaviour
{
public GUISkin Box;
public GUISkin Box2;
private string box;
public string gameName = "Your Game";
void OnGUI ()
{
if (Input.GetKeyDown(KeyCode.P))
{
GUI.skin = Box;
if(GUI.Button(new Rect(392,275,200,55),box))
{
LevelSerializer.SaveGame(gameName);
}
//GUI.skin = Box2;//This is my load button GUI Skin
//if(GUI.Button(new Rect(392,337,200,55),box))//This is my load button
foreach(var sg in LevelSerializer.SavedGames[LevelSerializer.PlayerName])
{
if(GUILayout.Button(sg.Caption))
{
LevelSerializer.LoadNow(sg.Data);
Time.timeScale = 1;
}
}
}
}
}
Comment
Best Answer
Answer by tw1st3d · Jul 10, 2013 at 09:55 PM
You're not creating any images. Here's an example of my load save screen.
void OnGUI()
{
if(LoadWanted)
{
GUI.skin = LoadSkin;
GUI.BeginGroup(new Rect(225, 55, 400, 500));
GUI.Box(new Rect(5, 7, 390, 74), "", "LoadTitle");
GUI.Box(new Rect(0, 0, 400, 500), "", "LoadBorder");
int y = 0;
GUI.BeginGroup(new Rect(11, 75, 376, 425));
saveList = GUI.BeginScrollView(new Rect(0, 0, 376, 425),
saveList, new Rect(0, 0, 356, 610), false, true);
foreach(var i in text)
{
if(GUI.Button(new Rect(0, y, 376, 20), i, "LoadLine"))
{
//LoadSkin.button.font.material.color = Color.yellow;
if(loadGame == i.ToString()){
//Load Game
}else{
loadGame = i.ToString();
Debug.Log("Trying to load: " + i.ToString());
}
Debug.Log(loadGame);
}
y = y + 20;
}
GUI.EndScrollView();
GUI.EndGroup();
GUI.Box(new Rect(0, 0, 400, 500), "", "LoadBorder");
if(GUI.Button(new Rect(358, -10, 50, 50), CloseBG))
{
LoadWanted = false;
}
GUI.EndGroup();
}
}
You have to call things like GUI.Box() to make an image come up.
I forgot to mention, you have to apply textures to your custom styles in a new GUISkin
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Is There A Way To Make Sprites Clickable? 1 Answer
In-Game GUI buttons don't work 2 Answers
Making my GUI Button Movable in Play mode 0 Answers
(C#) GUI Buttons not working 1 Answer