Hi everybody,
I am new to unity 3d and in order to learn it i am making an fps game.
But i have a problem:
I tried to do the shooting with bullets i mean i made a script that will instantiate a object as bullet but when i tried to add in there anything to destroy the objects after they will be shooted it always removed the “main” object so i got an error like “The prefab you want to instantiate is null”
Is there any function or script or command how to remove the bullet after they get instantiated?
I dont want to remove the “main bullet” so i can still shoot but the objects will keep removing…
Any help or any other way how to do shooting (i dont need bullets if there is other way and better) or so??
Any help is welcome…
If you need anything else write pls
Here is the script:
var shootSound : AudioClip;
var Bullet : Rigidbody;
var shootForce : float;
function Update () {
if (Input.GetButtonDown (“Fire1”) ) {
audio.PlayOneShot (shootSound) ;
var newBullet : Rigidbody = Instantiate (Bullet,transform.position, transform.rotation) ;
newBullet.name = “Bullet”;
newBullet.rigidbody.velocity = transform.
TransformDirection (Vector3 (0,0, shootForce));
}
}
@script RequireComponent (AudioSource)