- Home /
How can I use a font without GUI?
I am trying to change the font for my game and I have been reading the documents and stuff for it and they all say use the GUISkin and Style. The problem is, my class doesn't use MonoBehavior and, if I'm correct, you need MonoBehavior to call OnGUI. I was wondering, is there is a way to call a font without using OnGUI? If not, is there a way to revise my class to use MonoDevelop?
This is my Class
using UnityEngine;
using System.Collections;
public class DisplayCreatePlayerFunctions {
public static int classSelection;
private string[] classSelectionNames = new string[6] {"Mage", "Warrior", "Archer", "Monk", "Cleric", "Vampire"};
public GameObject Spawn;
public void DisplayClassSelections() {
//A list of toggle buttons and each button will be a different class
//Selection grid
classSelection = GUI.SelectionGrid (new Rect (50, 50, 250, 300), classSelection, classSelectionNames, 2);
GUI.Label (new Rect (1275, 50, 300, 300), FindClassDescription (classSelection));
GUI.Label (new Rect (700, 200, 300, 300), FindClassStatValues (classSelection));
}
public static string FindClassDescription(int classSelection) {
if (classSelection == 0) {
BaseCharacterClass tempClass = new BaseMageClass ();
return tempClass.CharacterClassDescription;
} else if (classSelection == 1) {
BaseCharacterClass tempClass = new BaseWarriorClass ();
return tempClass.CharacterClassDescription;
} else if (classSelection == 2) {
BaseCharacterClass tempClass = new BaseArcherClass ();
return tempClass.CharacterClassDescription;
} else if (classSelection == 3) {
BaseCharacterClass tempClass = new BaseMonkClass ();
return tempClass.CharacterClassDescription;
} else if (classSelection == 4) {
BaseCharacterClass tempClass = new BaseClericClass ();
return tempClass.CharacterClassDescription;
} else if (classSelection == 5) {
BaseCharacterClass tempClass = new BaseVampireClass ();
return tempClass.CharacterClassDescription;
}
return "NO CLASS FOUND";
}
}
Answer by Mmmpies · Dec 21, 2014 at 09:40 PM
Well this is guesswork but as you've managed to not get any answers so far maybe it'll help.
How about this, upgrade to 4.6 if not already on it. Oh and backup, backup, backup your projects first. Make sure you have a path back to where you are now.
Anyway if not on 4.6 backup then upgrade.
Then in using at the top add
Using UnityEngine.UI;
OnGUI is a behaviour of MonoBehaviour but I don't think the 4.6 UI is so just follow a few tutorials on the new UI or ask how to use the bit you need on here. In theory it should work.
Good luck
EDIT:
Well that's annoying. I got some free time so I thought I'd try this and it's fine up to the point where I copy the script onto a gameObject. Then it complains.
Turns out there is no way to have a script without MonoBehaviour be placed on a gameObject regardless of OnGUI or 4.6 UI.
Instead you need a script that does derive from Mono but also references the non-mono classes in your game setup and do the getting and setting of values. You could do a lot worse than watch BurgZerg tutorials for BaseCharacter and CharacterGeneration. 18 - 25 in the tutorials. here
Really sorry for sending you down the wrong path. I suppose the upside is you can use this method to continue using the OnGUI if you want.
Or if you want to get your version of BurgZergs BaseCharacter script ready and carry on using the new I'd be happy to continue the tutorial.
GUI is totally different to the old OnGUI. Looking at your code you want a selection box or "toggle group" type of effect to select a base class. Is that right?
Anyway first thing you need is a Canvas so GameObject - UI - Canvas.
Try that, it'll do nothing but add a canvas and event system to the Hierarchy.
Then right click the canvas and select UI - Text.
Type in some random text (or leave it as New Text).
Comment out any OnGUI lines from your code and lets see if the New UI will display the text and not complain about your scripts.
This is probably going to be slow task with a vertical learning curve! don't worry I'm starting to get my head round the new UI and have created selectable menus from List's which are just fancy arrays.
Alright, I added the canvas and some text to it, but what my script is doing is using a selection grid and whenever one of those buttons on the selection grid is selected, it will display the character description written for that character. How would I be able to do that with what I'm doing now?
O$$anonymous$$ watch this tutorial from @Bored$$anonymous$$ormon on here:
then watch the followup on creating a scripted menu of buttons from an array. Don't worry if the resolution stuff makes it look complex it's just an example of an array and you already have one of those.
See if you can create the second scriptable one, you'll have to follow the basic system to get you started.
If you get stuck at any point let me know where and with what.
And remember most people spends weeks trying to get something like this to work with the new UI so keep patient we'll get it done in a day or two.
Oh and it isn't going to make your display panel we just want something to setup a list of buttons that we can add a click event to.
I'll handle the display panel once we have the menu.
Your answer
Follow this Question
Related Questions
Is there a way to measure the pixel with/height of a string with a given font? 2 Answers
GUI text font change 3 Answers
Cant change color of 3dText/Text Mesh 3 Answers
How to make buttons in scene view? 1 Answer
Simple text in inspector components? 2 Answers