【发布时间】:2014-05-08 10:34:25
【问题描述】:
我在此脚本中遇到错误。
UnityEngine 不包含刚体的定义(第 22,24 行)
public class GunShoot : MonoBehaviour
{
public GameObject BulletPrefab;
public float BulletSpeed;
public int BulletsInClip;
public AudioClip GunshotSound;
void Update () {
if (Input.GetButtonDown("Shoot")){
Shoot();
}
}
void Shoot() {
var bullet = Instantiate(BulletPrefab, transform.Find("BulletSpawn").position, transform.Find("BulletSpawn").rotation);
bullet.rigidbody.AddForce(transform.forward * BulletSpeed);
audio.PlayOneShot(GunshotSound);
BulletsInClip--;
}
}
请告诉我要编辑什么,而不是只编辑脚本。
【问题讨论】:
-
您是在询问您是否在此脚本中遇到错误?此外,如果错误告诉您某些类型不包含刚体的定义,则意味着它不包含刚体的定义。
-
这就是它所说的。
bullet对象的类型不包含名称为rigidbody的成员。 -
它上面有一个刚体组件??
-
@Polynomial 请详细说明我需要做什么。
标签: c# unity3d game-engine