• 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 rowdyp · Feb 22, 2013 at 03:44 PM · guicolors

changing gui texture colors based on health

I want the players GUI texture to change color based on the players health however since you cannot use operators with int variables since something like the example below doesn't work I am out of ideas any help would be appreciated thanks again.

Example of what I tried

var healthTex : Texture2D; var healthMid : Texture2D;

function Update() { if(player health <= 50) { healthTex = health mid; } }

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
0

Answer by rowdyp · Feb 22, 2013 at 04:27 PM

Never mind I figured it out. I forgot to access my health variable from my other script thanks anyway ;)

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 appearance · Feb 22, 2013 at 04:32 PM

You can have an array of colors and make player's health int as an index in the array then you can assign the color to material's main color.

Ex:

 Color[] health_colors = { Color.black, Color.blue, Color.cyan, Color.gray, Color.green, Color.red, Color.magenta, Color.white, Color.yellow, new Color (255,0,0,255) };    
 int player_health = 50; 
 int color_index = player_health /10;
 renderer.material.color = health_colors [color_index];
 
 
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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

10 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

Related Questions

Text - Negative Color from Background 0 Answers

How to hook up the particle system to jump animation? 1 Answer

How to make a Keypad for a locked door 2 Answers

how big is my app size 2 Answers

Trying to Highlight text in order to copy and paste, but do not want the text to be editable. 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges