示例#1
0
    private void SpawnObject()
    {
        spawnPoint = Camera.main.ViewportToWorldPoint(new Vector3(
                                                          UnityEngine.Random.Range(0F, 1F), 1F, transform.position.z));

        Random     r       = new Random((int)Time.realtimeSinceStartup);
        GameObject spawnGO = pool.AllocateObject(spawnPoint, Quaternion.identity, r.Next(0, 3));

        spawnGO.GetComponent <Rigidbody>().velocity = Vector3.zero;
    }
示例#2
0
 void Update()
 {
     for (int i = 0; i < 100; i++)
     {
         var bullet = TowerPool.AllocateObject();
         if (bullet != null)
         {
             var bulletComponent = bullet.GetComponent <Bullet>();
             bulletComponent.OnEnd += TowerPool.DestroyObject;
             bullet.GetComponent <Rigidbody>().AddForce(bullet.transform.forward * 100);
         }
     }
 }