简体   繁体   English

unity 3d C# 播放器机芯差异

[英]Unity 3d C# player movement difference

What is difference between these two lines of codes?这两行代码有什么区别?

rb.velocity = new Vector3 (rb.velocity.x, 5f,rb.velocity.z); rb.velocity = new Vector3 (rb.velocity.x, 5f,rb.velocity.z);

rb.velocity = new Vector3 (0, 5f,0); rb.velocity = new Vector3 (0, 5f,0);

both codes are in the this logic (if (Input.GetButtonDown("Jump"))两个代码都在这个逻辑中(if (Input.GetButtonDown("Jump"))

In the first case you specify that velocity of your rigidbody should retain x and z value, and set y component of velocity to 5.在第一种情况下,您指定刚体的速度应保留 x 和 z 值,并将速度的 y 分量设置为 5。

In the second example, you set velocity to the numbers you given.在第二个示例中,您将速度设置为给定的数字。

If before setting value x and z values of rb.velocity were 0, both statements will do the same.如果在设置 rb.velocity 的值 x 和 z 值为 0 之前,两个语句将执行相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM