- Home /
How add this destory bullet to my autofire script?
My original shooting script was single fire only but it had a script where it deletes bullets after x amount of seconds. I have it set to 2. Here is the script that has the delete bullet thing. var projectile : Rigidbody ; var speed = 20;
function Update () {
if(Input.GetButton("Fire1"))
{
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection(Vector3 (0, 0, speed));
clone.AddForce(clone.transform.forward * 2150);
Destroy (clone.gameObject, 2);
}}
Line 11 is the line I would like to add to this script
#pragma strict
var bullet : GameObject;
private var shooting = false;
function Start() {
InvokeRepeating("Shoot", 0.0, 1.0 / bulletsPerSecond);
}
function Shoot() {
if (!shooting) return;
var go = Instantiate(bullet, transform.position, transform.rotation);
go.rigidbody.AddRelativeForce(Vector3.forward * 1750.0);
}
function Update(){
shooting = false;
if(Input.GetAxis("Fire1")){
shooting = true;
}
}
private var bulletsPerSecond = 6.0;
When I try to do this i get a compiler error saying clones is bad or something. Where do I add line 11 or whatever line to make this work?
Answer by robertbu · Jan 18, 2014 at 02:15 AM
I think what you are asking for is to insert between lines 14 and 15:
Destroy(go, 2.0);
Your answer
Follow this Question
Related Questions
How to destroy bullets? 2 Answers
How to change the fire rate on my shooting script? 1 Answer
How to do health thru network 1 Answer
Shoot towards mouse in Unity2D 2 Answers
Ultimate FPS not working correctly. 0 Answers