using System.Collections; using System.Collections.Generic; using UnityEngine; public class ball : MonoBehaviour { public int speed = 1; public double lifeTime = 5.0f; public double dist = 10.0f; private double spawnTime = 0.0f; // Use this for initialization void Start () { spawnTime = Time.time; } // Update is called once per frame void Update () { this.transform.position += this.transform.forward * speed * Time.deltaTime; dist -= speed * Time.deltaTime; if (Time.time > spawnTime + lifeTime || dist < 0) { Destroy(this.gameObject); } } }