rightBat.GetComponent<Rigidbody>().velocity = new Vector3(0f, 8f, 0f);
答案 0 :(得分:3)
嗯,rightBat.GetComponent<T>()
是一个返回传递给它的组件的泛型方法。在这种情况下,该组件是Rigidbody
。
之后,您将velocity
属性设置为新的Vector
。
您也可以使用
Rigidbody foo = rightBat.GetComponent<Rigidbody>();
foo.velocity = new Vector(0f, 8f, 0f);
但是在你的情况下无需创建临时变量 foo
,因此最好将其称为
rightBat.GetComponent<Rigidbody>().velocity = new Vector(0f, 8f, 0f);
答案 1 :(得分:0)
您可以尝试以下列方式查看上面的表达式
((rightBat).GetComponent<Rigidbody>()).velocity = foo;
或者,使用不同的分隔符(这不正确,但可能在视觉上更清晰)
[1]rightBat.[2]GetComponent<Rigidbody>()[3].velocity =[4] new Vector3();
[1]是你的对象(gameObject或其他组件)
[2]是一种方法(具有通用语法,因此&lt;&gt;()疯狂)
[3]是一个属性设定者 [4]是一个值