Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
1
Question by CallToAdventure · Dec 17, 2010 at 12:10 PM · guieditor-scriptingvariables

Advanced Scripting Features

Hi everyone,

I am working on a project and I have a couple of scripts with variables that need often change for tweaking purposes. My question is this: how do I go about and display on screen the variables in a GUI? Where do I have to look for that, I am not sure how to search for this in documentation (hence this long question); On the same scripts in the Inspector tab I want to display images instead of text; This is just to replace a long list of items and make it nice for the developer. That coped with what's visible on screen I am hoping to create a nice education way of presenting various script setups.

Thanks!

Comment
Add comment · Show 1
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 TowerOfBricks · Dec 17, 2010 at 01:42 PM 0
Share

Not a very good title, make it as descriptive as possible

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by TowerOfBricks · Dec 17, 2010 at 01:49 PM

To be able to display values in the game GUI and be able to change them is not very hard, here's an example (not tested)

public float myVariable = 5; public bool myOtherVariable = false;

public void OnGUI () { myVariable = GUILayout.HorizontalSlider (myVariable,0,100); myOtherVariable = GUILayout.Toggle (myOtherVariable); }

This will display the values on screen. There is no good way to display numbers-only fields in the game gui though, so I used a slider in the example instead.

To display stuff in the editor is a bit more tricky (or at least not as common or well documented) But you can read on here to get started. Extending The Editor - Unity Reference Manual

Hope it will help you get started.

Comment
Add comment · 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
-2

Answer by slkjdfv · Dec 28, 2010 at 09:05 PM

this is another example on how to display a variable.

Using UnityEngine

Using System.Collections

public class exampleScript : MonoBehavior

{

public float myVariable = 5;

public void OnGUI () { GUILayout.Label((int)myVariable)

}

}

what (int) does is typecasts myVariable to an integer, in other words it just drops the decimal point and doesn't round. I find type casting comes in handy when you need a float and integers wont work or visa versa.

Comment
Add comment · Show 2 · 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 _Petroz · Dec 28, 2010 at 09:39 PM 0
Share

That is not how you cast, angle brackets are for generics. To remove decimal places you shouldn't cast anyway, ins$$anonymous$$d use $$anonymous$$athf.FloorToInt. Also you should format your code.

avatar image slkjdfv · Dec 30, 2010 at 06:41 AM 0
Share

thank you i meant to put parenthesis, its all edited now.

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Copy/Paste GuiStyle in the Inspector 4 Answers

Resizing an array of gameObjects 2 Answers

Assign Color[] var in prefabs using Editor Scripting 1 Answer

How to access a non static variable by another static variable? 1 Answer


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