Heres My Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletController : MonoBehaviour
{
public float moveSpeed, LifeTime;
public Rigidbody RB;
public GameObject impactEffect;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
RB.velocity = transform.forward * moveSpeed;
LifeTime -= Time.deltaTime;
if (LifeTime <= 0)
{
Destroy(gameObject);
}
}
private void onTriggerEnter(Collider other)
{
Destroy (gameObject);
Instantiate(impactEffect, transform.position, transform.rotation);
}
}