Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 matthewsladebooman · Aug 10, 2019 at 11:37 PM · uihealth barhealth

How do I create a health system composed of multiple images?

Disclaimer: I should probably mention this now: Since I've decided to just instead learn the engine on my own as I used it and developed software for it, just like learning a board game as you've played instead of going over the whole manual, you can probably expect me to ask questions frequently about different matters, even if they seem outside my skill level. I've decided I wouldn't feel comfortable starting small and going up from there; I've decided to just start on potentially big(ger) projects split up into smaller ones and just simply learn the engine and its syntax as I went, since I personally don't think following YouTube tutorials is going to help much, at least not with starting small. Yes, there might still be some content I could learn from, but I'm just going to stick to learning as I use the engine the majority of the time. I know it seems like I'm doing a very bad practice, I'll admit, but I've decided that's just the way I wanted to go if it works for me. Thanks for listening.


Also, this is just the basic process on how to form the base health system, I may need further help with decreasing/increasing health or dynamically adjusting maximum health, among other things.


Basically, I'm trying to work on a health system for my Princess Peach fangame prototype, and I have absolutely no idea which direction to go at this point. I plan on using a single UI sprite copied over ten sections which can go down by touching an enemy or just simply pressing a button as debug. My "final" code is supposed to copy the heart units over to their corrasponding places as in an order via rectTransform, but for whatever reason that I cannot figure out, the sprites actually get "bunched up" in a very incorrect place on the screen, rather than as intended. In one of the screenshots, the sprites end up in the very top near left corner of the screen. Actually, they aren't actually bunched up; the code actually generated "ghost" sprites that do not show up at all even when within the usual rectTransform boundaries; they're basically invisible - and they're enabled, so they're technically supposed to show up in the first place. As one other thing, the code actually produces way too many of these sprites, rather than the 10 I've intended.


I should also mention the key word "fangame"; I know that being a website for potentially professional programmers, that this may be strongly frowned upon, but y'all could just make an exception to this, since the problem would refer to a general setting anyway, and that's just the way I've decided to do things anyway, so it's all okay. Also, I know I am using Nintendo assets, but for the same reasons I've mentioned, it should be all fine.


I'm using UI sprite elements for this process, and the images and "final" code will all be displayed at the bottom. The top image is where the unnecessarily high amount of UI sprites generated by the code itself are, and the strange and unintended way they're laid out in the hierarchy, as well as the incorrect placement of the "hearts" themselves. And pay attention to the Rect X Positions on the very bottom right of the second image in the two sections of it; this is where the latter problem is occurring with the "ghost" UI sprites. The "final" code can be dissected to figure out the potential problem with the code, if there is any.


alt text


alt text


 // Start is called before the first frame update
     void Start()
     {
         //Instantiate(Heart, HeartPosition);
         //HeartRectPosition.anchoredPosition = new Vector2(30, 0);
         
         for (int HeartY = 0; HeartY < 2; HeartY++)
         {
             for (int HeartX = 0; HeartX < 5; HeartX++)
             {
                 HeartRectPosition.anchoredPosition = new Vector2(-200 + (30 * HeartX), 100 + (26 * HeartY));
                 Instantiate(Heart, HeartRectPosition);
             }
         }
     }



If you need any further information, please let me know. Thanks for listening. Have a nice day.

error1.png (158.9 kB)
error4.png (66.6 kB)
Comment
Add comment · Show 3
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 Hellium · Aug 11, 2019 at 10:22 AM 0
Share

Unity already has components to layout UI elements

https://docs.unity3d.com/$$anonymous$$anual/script-GridLayoutGroup.html

avatar image matthewsladebooman Hellium · Aug 11, 2019 at 01:17 PM 0
Share

Thanks for the mention; I didn't even think it even existed. I'll try that out.

avatar image matthewsladebooman · Aug 11, 2019 at 09:03 PM 0
Share

I've been working with the GridLayoutGroup among other things, but now I'm stuck again; I don't know how to position the icons to different places, nor do I know how to space them along a certain number of tiles right or left before going down or up. Also, there seems to be an "empty" spot where the "first" tile should've been, and I don't understand this problem either. Thanks for more help.

0 Replies

· Add your reply
  • Sort: 

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

184 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

Related Questions

How can I create a UI element and attach my script to it for a functional health bar? 1 Answer

I need help with the player's health points 1 Answer

How to make a Health Bar? 1 Answer

How to make a health bar in Unity 5? 0 Answers

Damage Indicator not showing correct position of attack. 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