using UnityEngine; public class Projectile : MonoBehaviour { public float speed = 1.0f; public float maxLifeTime = 100f; private float currentLifeTime = 0f; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { } // Update is called once per frame void Update() { Vector3 direction = transform.forward; transform.position = transform.position + (direction.normalized * Time.deltaTime * speed); currentLifeTime += Time.deltaTime; if (currentLifeTime >= maxLifeTime) { Destroy(gameObject); } } private void OnCollisionEnter(Collision collision) { Destroy(gameObject); } }