Unity javascript error Rigidbody
Unity javascript error Rigidbody
#pragma strict
private Rigidbody rb;
function Start () {
rb = GetComponent<Rigidbody>();
}
function FixedUpdate () {
var v : float = Input.GetAxis("Vertical");
var h : float = Input.GetAxis("Horizontal");
Vector3 movement = new Vector3 (h, 0.0f, v);
rb.AddForce (movement);
}
如果能给我一个带代码的答案,我将不胜感激。谢谢你花时间回复。
您在代码中混合了Javascript和C#。它们是两种不同的语言。以下是问题:
private Rigidbody rb;
、rb = GetComponent<Rigidbody>();
和Vector3 movement = new Vector3 (h, 0.0f, v);
。
我建议你立即切换到C#,因为Unity建议你这样做。大多数最新的文档都没有Javascript的示例,而且看起来Javascript支持在未来将被删除。
我把坏代码注释掉了,这样你就可以从错误中吸取教训。这是你的固定代码:
#pragma strict
//private Rigidbody rb;
private var rb:Rigidbody;
function Start () {
//rb = GetComponent<Rigidbody>();
rb = GetComponent.<Rigidbody>();
}
function FixedUpdate () {
var v : float = Input.GetAxis("Vertical");
var h : float = Input.GetAxis("Horizontal");
//Vector3 movement = new Vector3 (h, 0.0f, v);
var movement = Vector3(h, 0.0f, v);
rb.AddForce (movement);
}
相关文章:
- jQuery Error adadvisor.net
- Ajax调用ERror Cross Origin REquest:在rails中自动完成大学列表
- 类型error primeFactors.for不是函数
- Array.every返回false,而不是类型error
- datatables.net ajax error - http://datatables.net/tn/7
- Error: timers.js:234 callback.apply(timer, args);
- 滚动到错误字段ERROR
- Error with xmlhttpresponse
- ajax javascript 500 error
- 将数据从ExpressJS发送到AngularJS ERROR json
- walkscore API JSON error
- STRIPE.JS Error
- Angular Routing Pretty URL Error
- 节点回调参数无法断言instanceof Error
- Jasmine .calls.count and .calls.any throwing error
- React.render error
- 如何访问npm模块抛出的自定义错误对象[error:[object object]]
- grunt contrib jshint-error在定义之前就已经使用过了
- Javascript getElementById null error
- Unity javascript error Rigidbody