在vector3中将值更改为1到1以上(Change values above 1 to 1 in a vector3)

系统教程 行业动态 更新时间:2024-06-14 17:01:34
在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)

更多推荐

本文发布于:2023-04-20 18:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/07de33c39fc95dee0badce2b610564e1.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中将   values   Change

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!