I have a character that shoots simple arrow prefabs and a timer that destroys them after a short amount of time however it is destroying the base object preventing the game from instnatiating anymore in the future.`using UnityEngine;
using System.Collections;
public class Destroy_Bullet : MonoBehaviour
{
//floats
public float bulletTimer = 1.9f;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
Destroy (gameObject, bulletTimer);
}
}`
Any help would be greatly appreciated.
You overwrite your prefab-Variable with this:
mPF_Arrow = (Rigidbody) Instantiate(mPF_Arrow, transform.position+(transform.forward*-1), transform.rotation);
Use an extra variable for this:
RigidBody myRb = (Rigidbody) Instantiate(mPF_Arrow, transform.position+(transform.forward*-1), transform.rotation);
And then set the force for this variable:
myRb.AddRelativeForce (Vector3.back * bulletForce);
AlwaySunny is correct. It looks like you are setting your clone to mPF_Arrow and mPF_Arrow is also your prefab reference. So the prefab reference is getting destroyed. The left side of your equals sign should be “Rigidbody clone =” clone would be the new instance of mPF_Arrow