Hi!! Im new to unity. I have my gun script, spawn point, bullet, and gun.
heres my script.
var Bullet: Transform;
function Update () {
if (Input.GetButtonDown ("Fire1")){
var bullet=Instantiate(Bullet,GameObject.Find("Gun_Spawn").transform.position,Quaternion.identity);
bullet.rigidbody.AddForce(transform.forward *2000);
}
}
but every time I hit Fire1 (Left mouse) the bar at the bottom of the screen says,
Theres no rigidbody attached to clone, script still searching?? I dont know what to do??
and I also need a script to destroy the bullet. Can any body help?? Thank you for the time.
You are saying: `bullet.rigidbody`. But the bullet doesn't have one. Unity3D throws you a `NullReferenceException`. To solve this: add a new RigidBody component.
If your bullet is a prefab, you can just add it in your editor.
If it is a class that you are creating from code somehow, use a script: