public void Tick(float delta_time) { var enumerator = all_bullet_gameobj.GetEnumerator(); while (enumerator.MoveNext()) { BulletGameObject bullet_obj = enumerator.Current.Value; // tick 操作里不要做destory 操作 bullet_obj.Tick(delta_time); } }
public void DestroyBulletGameObject(int bullet_id) { if (all_bullet_gameobj.ContainsKey(bullet_id)) { BulletGameObject bullet_game_obj = all_bullet_gameobj[bullet_id]; if (bullet_game_obj.bullet_obj != null) { ObjectPoolManager.Instance().ReturnObject("Missil_01", bullet_game_obj.bullet_obj); bullet_game_obj.bullet_obj = null; } all_bullet_gameobj.Remove(bullet_id); } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { //The Bullet instantiation. GameObject BulletGameObject; Temporary_Bullet_Handler = Instantiate(bullet, bulletEmitter.transform.position, bulletEmitter.transform.rotation) as GameObject; //Retrieve the Rigidbody component from the instantiated Bullet and control it. Rigidbody Temporary_RigidBody; Temporary_RigidBody = BulletGameObject.GetComponent <Rigidbody>(); //bullet being pushed Temporary_RigidBody.AddForce(transform.forward * bulletForwardForce); //Destroy the unncessary components Destroy(BulletGameObject, 3f); } }
public void CreateBulletGameObject(int bullet_id) { BL.BulletComponent bullet_com = BL.BLBulletManager.Instance().GetBullet(bullet_id); if (bullet_com != null) { BulletGameObject obj = new BulletGameObject(); obj.bullet_id = bullet_id; obj.bullet_obj = ObjectPoolManager.Instance().GetObject("Missil_01"); obj.bullet_obj.transform.SetParent(UnitManager.Instance().cache_root_effect_node, false); Vector3 start_pos = bullet_com.start_postion.Vector3Value(); Vector3 end_pos = bullet_com.end_position.Vector3Value(); Vector3 bullet_dir = (end_pos - start_pos).normalized; obj.bullet_obj.transform.position = start_pos; obj.bullet_obj.transform.rotation = Quaternion.LookRotation(bullet_dir); all_bullet_gameobj[bullet_id] = obj; } }