I want to make it so that after i shoot in my shooting script the bullet is destroyed after x amount of time but i cant figure out how nothing is working ive tried call destroy in and out of the function and it wont work please help!?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shooting : MonoBehaviour {
public Rigidbody2D bullet;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("Fire1"))
{
Rigidbody2D clone;
clone = Instantiate(bullet, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection(Vector2.up * 15);
DestroyObject(clone, 1f);
}
}
}