private void Fly() { //飞行中目标已销毁,销毁子弹,相应的攻击协程因为挂载的物体被销毁自动取消 if (!target) { Destroy(gameObject); isReached = true; } //向目标移动 else { transform.Translate((target.transform.position - transform.position).normalized * Time.deltaTime * PublicData.bulletSpeed, UnityEngine.Space.World); } if (Vector3.Distance(target.transform.position, transform.position) < PublicData.cubeSize * 0.3f) { isReached = true; if (spaceObjectPrefab != null) { GameObject attackSpaceObject = Instantiate(spaceObjectPrefab); attackSpaceObject.transform.position += target.transform.position; attackSpaceObject.transform.SetParent(GameObject.Find("AttackSpace").transform); Space attackSpace = attackSpaceObject.GetComponent <Space>(); attackSpace.StartCoroutine(attackSpace.AttackReach(attackResultMode, attackValue, null, PublicData.noMeaning)); } Destroy(gameObject); } }