Possibles Range of Values that can be set using inspector, var testInt : int;

Hi,
Consider the following Script

//my integer variable
var intValue : int;

function Update(){
       
       print( intValue );

}

the above code will print the value what ever it will be set in the inspector.

I want to apply the constraint on the possible range of values that can be set in the (var intValue : int; )
intValue variable. in inspector.

for example i want to apply the constraint that the variable intValue should only contain value between 0 - 100

how can i do that, is there any method to set this type of constraint.

Edit: one way could be to use the editor script that would check if value entered is more than upper limit and set the set the upper limit value, and for lower limit vise versa

This would be really cool thing if it is possible…

I also need this…

You could try out ExecuteInEditMode and a Mathf.Clamp(intValue, 0, 100) in your Update function.

Try the Range attribute

[Range(0, 100)]
public int Probability = 50; // 0 - 100

This will show up as a slider in the Inspector.

Here’s a blog post that has some more on the subject – I didn’t read the whole thing since the Range attribute does what I want.
http://angrytroglodyte.net/home/index.php/how-we-do-it/tech-blog/75-making-unity-work-for-you

1 Like