在vector3中将值更改为1到1以上(Change values above 1 to 1 in a vector3)
我有一个带有这些值的vector3:
Vector3 bla = new Vector3(1.0f,8.0f,16.0f);我希望每个高于1的值都是1,是否有一种简单的方法可以做到这一点? 我可以编写一个函数来完成它,例如:
void ValueToOne(Vector3 _input) { float x = _input.x / _input.x; float y = _input.y / _input.y; float z = _input.z / _input.z; return new Vector3(x,y,z); }但我想也许Unity已经有了这样的事情呢?
提前致谢!
I have a vector3 with these values:
Vector3 bla = new Vector3(1.0f,8.0f,16.0f);I want every value that is higher then 1 to be 1, is there an easy way to do that? I could write a function to do it, like:
void ValueToOne(Vector3 _input) { float x = _input.x / _input.x; float y = _input.y / _input.y; float z = _input.z / _input.z; return new Vector3(x,y,z); }But I thought maybe Unity has something to do that already?
Thanks in advance!
最满意答案
您可以使用Vector3.Min函数执行此操作:
Vector3 clampedVector = Vector3.Min(Vector3.one, yourVector)You could use Vector3.Min function to do this:
Vector3 clampedVector = Vector3.Min(Vector3.one, yourVector)更多推荐
发布评论