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
0
Question by oliver-jones · May 17, 2011 at 12:23 PM · transformpositionplanealignmentleft

Health Bar Alignment Issue

Hello,

I have a health bar system on my enemy which is a game object plane that simply decreases in size according to the health variable. The only slight problem I'm having is that the plane decreases on both sides, where as I only want it to decrease on the right side. So its alignment is always left.

Here is a video to get a better understanding: http://www.youtube.com/watch?v=qZ3K36wlTc4

So what I was thinking is maybe I could reposition the plane every time the health variable goes down:

// This changes the size of plane: HealthBar.transform.localScale.x = MaxBar * (Health/MaxHealth);

// This to be used for alignment? \\ HealthBar.localPosition = Vector3((keep aligned left), 60, -5);

// MaxBar = Size of the plane in 'X' // MaxHealth = Total health // Health = Current health of enemy

But I don't know how to keep it left, could I change the origin?

Please help, thanks!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
-1
Best Answer

Answer by almo · May 17, 2011 at 12:26 PM

I think you need to attach the healthbar to another (invisible) object so the place you want centered is at the center of the other object, and resize the other object.

Example:

Your healthbar is 2 units long. You make a blank object at 0, 0, 0. You then attach the healthbar to the blank. Then you set the healthbar's X coordinate to 1, 0, 0. Now the edge of the bar should be at the pivot point of the blank. Then scale the blank, and the edge of the bar should remain stationary.

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
0

Answer by Scribe · May 17, 2011 at 12:39 PM

Can you not use GUI's instead of having a plane?

GUI.BeginGroup (new Rect(10, 10, health, 30));
GUI.DrawTexture(new Rect (0, 0, Tex.width, Tex.height), Tex, ScaleMode.ScaleToFit);
GUI.EndGroup ();

you have this ^ in an OnGUI function and set the health to a number that represents the amount of health you have left (if you want it bigger or smaller you could do health*2 or health*0.75)

then you have your Tex could be a plain colour or a pattern or a gradient going green to red?

at the top add var Tex : Texture2D; and choose a texture

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

1 Person is following this question.

avatar image

Related Questions

What is the reasoning of multiplying by Time.deltaTime 1 Answer

does not work check if dead 1 Answer

Help around an approach to a "Virtual Motion Table" in Unity 0 Answers

Camera movement 1 Answer

GameObject position and localPosition not changing in hiearchy, only in script. 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