Ejemplo n.º 1
0
 // Update is called once per frame
 void Update()
 {
     cubesInUse.text        = cubes.InUse.ToString();
     cubesAvailable.text    = cubes.Available.ToString();
     spheresInUse.text      = spheres.InUse.ToString();
     spheresAvailable.text  = spheres.Available.ToString();
     capsulesInUse.text     = capsules.InUse.ToString();
     capsulesAvailable.text = capsules.Available.ToString();
     // Let's spawn at random every 75ms
     counter += Time.deltaTime;
     if (counter >= 0.075f)
     {
         counter = 0f;
         // Get an element from the pools
         int tmpInt = Random.Range(1, 10000);
         if ((tmpInt % 2) == 0)
         {
             tmpObj = spheres.GetElement();
         }
         else if ((tmpInt % 3) == 0)
         {
             tmpObj = cubes.GetElement();
         }
         else
         {
             tmpRB  = capsules.GetElement();
             tmpObj = tmpRB.gameObject;
         }
         // Position the element
         tmpObj.transform.position = new Vector3(Random.Range(-6f, 6f), Random.Range(10f, 14f), Random.Range(-6f, 6f));
     }
     // Let's optimize our pools
     cubes.Optimize();
     spheres.Optimize();
     capsules.Optimize();
 }