[英]Unity3D: Is there a easy way to give a min/max to a value in the inspector?
I am trying to figure out how to give a minimum and maximum to a value in the inspector. 我试图弄清楚如何在检查器中给最小值和最大值。
For example: 例如:
public float testValue;
I know I can set a minimum and maximum in the code with if/else statements, but that is going to be a mess with a lot of variables. 我知道我可以使用if / else语句在代码中设置一个最小值和最大值,但这将给很多变量带来麻烦。 This TestValue will be visibile in the Unity inspector. 该TestValue将在Unity检查器中可见。
I want to make it possible that the maximum of this value is 100 and the minimum is 0. Is there a fancy way to do this instead of a lot of statements? 我想使此值的最大值为100,最小值为0。是否有一种花哨的方法可以代替很多语句呢?
Thanks in forward :) 谢谢前进:)
尝试这个 :
[Range (0f,100f)] public float testValue;
Possible this one 可能这个
[Range(0.0f, 10.0f)]
public float mySliderFloat;
There is indeed a fancy way to do this. 确实有一种花哨的方法可以做到这一点。 With the Range declaration: [Range(min, max)]
使用范围声明: [Range(min, max)]
https://unity3d.com/learn/tutorials/topics/tips/show-public-variables-sliders-rangemin-max https://unity3d.com/learn/tutorials/topics/tips/show-public-variables-sliders-rangemin-max
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.