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