看自学网上的Unity3D的视频,其中视频中的实力代码:

n.rigidbody.AddForce(fwd * 28000);

这个代码运行会出现错误:

BCE0144: 'UnityEngine.Component.rigidbody' is obsolete. Property rigidbody has been deprecated. Use GetComponent<Rigidbody>() instead. (UnityUpgradable)

BCE0019: 'AddForce' is not a member of 'UnityEngine.Component'

字面意思很容易理解,说这个rigidbody的方法已经被淘汰了,请使用GetComponent方法来代替

Unity3D第5版的写法是这样的:

n.GetComponent(Rigidbody).AddForce(fwd * 28000);

值得在强调一遍的是:Javascript代码中注意大小写!

学习地址:

由于平台限制,网站链接添加,如果需要学习Unity3D,请百度:我要自学网

05-11 11:05