• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by CrispyCarry · Dec 21, 2014 at 10:01 AM · guifontcustomno

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";
     }
 
 }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 13 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CrispyCarry · Dec 22, 2014 at 07:20 PM 0
Share

What part of the new UI am I supposed to be adding?

avatar image Mmmpies · Dec 22, 2014 at 07:34 PM 0
Share
  1. 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.

avatar image CrispyCarry · Dec 22, 2014 at 07:59 PM 0
Share

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?

avatar image Mmmpies · Dec 22, 2014 at 08:18 PM 0
Share

O$$anonymous$$ watch this tutorial from @Bored$$anonymous$$ormon on here:

BasicButton$$anonymous$$enu

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.

Scriptable$$anonymous$$enu

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.

avatar image Mmmpies · Dec 22, 2014 at 08:40 PM 0
Share

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.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Is there a way to measure the pixel with/height of a string with a given font? 2 Answers

Drawing Editor Inspector GUI based on selected/current prefab (CustomPropertyDrawer) 2 Answers

Why does the font selected for my GUI Skin not display correctly? 1 Answer

Make GUI bigger and another font? 2 Answers

GUI Label Width & Height 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges