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 Arshia001 · Jul 18, 2011 at 10:12 AM · texturemix

Mixing two textures

I'm trying to mix two textures together. One is an empty health bar texture and the other the full counterpart. When the health bar is, say, half empty, there should be the right half of the empty bar and the left half of the full part on the screen.

I tried drawing both as seperate textures, but the clipping modes don't include "align right" and "align left" (or at least non that I know of) so I can't do that. Also tried declaring a new texture in code and filling it with pixels from the two textures, but it EATS up processor power, reducing my framerate from 500fps to 30fps. What should I do? Tnx in advance.

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

Answer by DavidDebnar · Jul 18, 2011 at 10:21 AM

When it's an healthbar, than don't try to mix them. Instead of that just multiply. Draw the 2 textures, and than multiply the health texture/that texture that will be filling it up, by health. And if you don't wan't to deform the texture, than you have to make 3 textures. Background, the texture that will be filling it up and a texture that will hide the unfilled parts. Like the opposite. You won't make the filling texture bigger, but you will make the hiding texture, that will be colored the same as the background smaller.

  • David

Comment
Add comment · Show 5 · 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 Arshia001 · Jul 18, 2011 at 04:59 PM 0
Share

I can see what you're telling me to do, but I don't really know how to do it in code! Could you please provide a bit of source code for doing this? Tnx. Oh, and BTW, I don't wanna deform either of the textures.

avatar image DavidDebnar · Jul 18, 2011 at 09:21 PM 0
Share

So u wan't the third method. Like imagine that this O is the health that will be going smaller, and this X is both background and the texture that will be going on the health. So what you wan't to do, is to stretch the texture, or whatever, so it will be bigger as the health is smaller like this. So you aren't defor$$anonymous$$g the health, just hiding a part of it.

OOOOO OOOOX OOOXX OOXXX OXXXX XXXXX

And well the script.. It's 1 at morning and I needed a really big strength to get this outta my head :D. Ummm. What you wanna do is to make a gui texture trough code, and it's x and y size/the one that you wanna change, will be variables. Than let's say that the maximum health is 100. $$anonymous$$imum 0. So you have a 3 gui - 1. the health image, 2. the background image, 3. the background image second time, we will be resizing this one. So the code will look like this.

var lengthX : float = 0; var hp : float = 100;

function TakeDamage() { hp -= damage; }

function OnGUI() { //draw the health image, make it's depth smaller //draw the background, make it's depth bigger that the hp image, but smaller than the hiding image we are gonna resize. lengthX = 100 - hp; //lengthX set to maximum health $$anonymous$$us the current one GUI.DrawTexture(Rect(100-lengthX,0,lengthX,10), texture, Scale$$anonymous$$ode.ScaleToFit, true, 0.0); }

I don't know if this is going to work, but it should. You might wan't to max out the last float in the DrawTexutre, because it's the aspect ratio and you might wan't to change that. Google the depth, if you dont know the know how.

  • $$anonymous$$

avatar image Arshia001 · Jul 18, 2011 at 09:40 PM 0
Share

It was 1 A$$anonymous$$ 18 $$anonymous$$utes ago, so you should be from somewhere around eastern Europe, if I'm not totally mistaken! :D Tnx for the code!

avatar image DavidDebnar · Jul 19, 2011 at 09:36 AM 0
Share

Can you close the question? ^.^

avatar image Arshia001 · Jul 19, 2011 at 04:36 PM 0
Share

how do you do that?

avatar image
0

Answer by Arshia001 · Jul 19, 2011 at 04:35 PM

I also found another way to do it. Just add a new style to your GUI skin, such as "full health" and set the normal state's texture to the full health texture. do the same with the empty texture and another style. In the draw code, figure out the width of the full portion (let's name it f). Set the "full health" style's Border.left property to f (make sure others are zero) and draw a box which is f pixels wide using the full health style. Do the same for the empty health texture, only set Border.right instead. Works perfectly.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Assigning UV Map to model at runtime 0 Answers

mix diffuse with alpha channel 1 Answer

Change GUI.Button Texture on runtime 1 Answer

Change crosshair text when hitting a trigger 0 Answers

How to achieve realistic models 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