- Home /
Clarification on how RangeAttribute works
I'm adding regenerating health/mana/etc to my game now, and I'm a bit confused about how to keep each attribute from rising above a maximum value. Let's say I want HP to max out at some float maxHP, can I simply go:
 float maxHP = 100;
 [Range(0f, maxHP)]
 public float myHP;
and rest assured that myHP = 100+25 will always return 100, and myHP = 0 - 100 will always return 0? Or is range not intended for this?
Answer by bubzy · Oct 27, 2014 at 07:21 AM
 if(myHP > maxHP)
 {
 myHP = maxHP;
 }
http://unity3d.com/learn/tutorials/modules/intermediate/scripting/attributes for the range thing
Isn't this a little cumbersome compared to using a clamp or range, though?
Not really, i dont know how the compiler works but i guess that this would take less instructions to process
Your answer
 
 
             Follow this Question
Related Questions
Finding Distance between Angles and Points 2 Answers
Multiple Cars not working 1 Answer
Issue with Adding Quaternions 1 Answer
A problem with intersection detection 1 Answer
Distribute terrain in zones 3 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                