- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
rellissc · Sep 18, 2013 at 09:48 PM ·
c#guitexture
Changing the size of a guiTexture as a health bar (using C#)
I wrote some code based on an answer to a similar question where the person used JavaScript to illustrate. However, whenever I try it the way they suggest, I get a "Cannot modify a value type return value of 'UnityEngine.GUITexture.pixelInset'. Consider storing the value in a temporary variable" message;
Here is the code that is pulling up the error.
//This is inside the Update function
// healthBar is the GUITexture that I assigned in the Inspector
healthBar.pixelInset.width = originalWidth*health/100f;
Comment
Answer by robertbu · Sep 18, 2013 at 09:51 PM
With C#, you have to move the information into a temporary, modify the temporary, and then reassign the values:
Rect rect = healthBar.pixelInset;
rect.width = originalWidth*health/100f;
healthBar.pixelInset = rect;
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Touch gui texture buggy 0 Answers
Load a sprite as a texture from. 1 Answer
C# - Enabled GUITexture already, but I can still click it. 2 Answers