Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
0
Question by yannikarlaftis · May 15 at 05:56 AM · uivariabledisplaystats

Best way to show variable values on UI

I know I can simply make a bunch of UI texts on a panel and drag each variable one after the other in their respective position, but with how many variables I want to display, I feel as if this approach is way too slow and a waste of time. I have at least 10 of these variables all in the same script and was wondering if there is a much more efficient way of displaying these variables on the player UI without dragging and dropping them over and over again.

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 gernomino · May 15 at 12:36 PM

Couple options though don't know that any are really ideal. This is one of the issues I have on a regular basis.
- Could create a prefab with the options set
- Could add a menu item that creates the player and sets any defaults you want. https://docs.unity3d.com/ScriptReference/MenuItem.html
- On the menu item above, you could also create a custom asset in a scriptable object to store the player data for that instance.


It would be cool if you could select assets from multiple folders in Unity and then drag them over all at once, having it apply them to the object in the order you clicked them.


Code example for one of my use cases. Has some of methods 2 and 3 in it.

 public class TerrainMenu : MonoBehaviour
 {
     // Put the item under the existing GameObject/3D Object menu
     [MenuItem("GameObject/3D Object/RTS Terrain")]
     static void CreateTerrain()
     {
          // ----- Creating a GameObject in the scene ------ //
          GameObject _terrain = new GameObject();
         _terrain.tag = "Terrain";
         _terrain.layer = LayerMask.NameToLayer("Terrain");
         _terrain.name = "Terrain";
         GameObjectUtility.EnsureUniqueNameForSibling(_terrain);

         // ----- Creating a custom asset and saving it to a file ----- //
         // TerrainData inherits from ScriptableObject
         TerrainData _terrainData = TerrainData.CreateInstance<TerrainData>();
         // Can call any other setup functions you need or set defaults on the scriptable object
         _terrainData.Initialize();
         // Save to a file
         string filePath = AssetDatabase.GenerateUniqueAssetPath("Assets/terraindata.rtsterraindata.asset");
         AssetDatabase.CreateAsset(_terrainData, filePath);
         // My heightmap is a texture2D so I need to save it separately. Still figuring out how this works.
         AssetDatabase.AddObjectToAsset(_terrainData.heightMap, filePath);
 
         // I need to add the script I made to the game object (in your case it would be your player script).
         RTSTerrain _script = _terrain.AddComponent<RTSTerrain>();
         // Finally I need to tell the script about my asset.
         _script.terrainData = AssetDatabase.LoadAssetAtPath<TerrainData>(filePath);
     }
 }



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

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

235 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to display Damage & Armor Stats in UI 1 Answer

Creating random NPC’s with their own stats. 1 Answer

Displaying variable on UI text every frame (JS) 1 Answer

Optimal way to display a player's health with hearths? 1 Answer

Variable Vs Array? 2 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