using System.Collections; using System.Collections.Generic; using UnityEngine; public class BulletFly : MonoBehaviour { public float fSpeed = 10.0f; public float fLifeTime = 0.5f; public float fDist = 10000.0f; Transform tr; float fSpawnTime = 0.0f; // Use this for initialization void Start () { tr = transform; fSpawnTime = Time.time; } // Update is called once per frame void Update() { tr.position += tr.forward * fSpeed * Time.deltaTime; fDist -= fSpeed * Time.deltaTime; if (Time.time > fSpawnTime + fLifeTime || fDist < 0) { Destroy(this.gameObject); } } }