- Home /
How to give a warning in the inspector window if a value (speed) is greater than 10? (C#)
How to make this? If I change something in the inspector window how to check it if it's greater than 10 and if it is, then give a warning until the user change it?
Do you want the user to be allowed to put in value above ten but with a warning or do you want it to be impossible to input a value above ten? For the latter you can easily just use the Range attribute. If you have not used attributes before then here is the tutorial (includes example of the range attribute).
I want the user not to be allowed to put number <0
. So the negative numbers are not alowed.
Then the RangeAttribute works perfectly fine for that. If you want any more complicated behavior/limitations then you need to create your own custom inspector or your own custom attribute.
"Infinity" would be the maximum number allowed which is: int.$$anonymous$$axValue or float.$$anonymous$$axValue.
Because this creates a slider, it will be very hard to input accurate numbers at such a large range, but you can still input numbers manually in the box next to the slider.
Answer by fafase · Jan 23, 2015 at 08:28 AM
you can prevent the user from giving larger value than 10:
[Range(0,10)]
[SerializeField]
private int myInt = 0;
if you want the warning you would have to go through Editor script to get and check the value. I would use the above.
Your answer
Follow this Question
Related Questions
How to get notification of moving a GameObject in the hierachy when editing the scene? 1 Answer
Unity editor not saving object changes 4 Answers
Creating a custom inspector utilizing a list of class instances with serialization? 1 Answer
Multiple scripts reference to the same SerializeField 1 Answer
Align text into PropertyField 1 Answer