示例#1
0
    public void SpawnObstacle(Vector3 position, Vector2i lane)
    {
        if (!m_Death)
        {
            int random = Random.Range(0, m_ObjectPool.Count);
            if (m_ObjectPool.Count > 0)
            {
                ObstaclePair fromPool = m_ObjectPool[random];

                if (fromPool.data.CanSpawn(lane))
                {
                    m_ObjectPool.RemoveAt(random);

                    fromPool.obstacle.transform.position = new Vector3(position.x, position.y, 20);
                    fromPool.obstacle.gameObject.SetActive(true);
                    fromPool.SetLifetime(4);
                    m_ObjectsInUse.Add(fromPool);
                }
            }
            else
            {
                Debug.LogError("Pool Empty...");
            }
        }
    }
示例#2
0
 public void InitializeObjectPool()
 {
     m_ObjectsInUse = new List <ObstaclePair>();
     m_ObjectPool   = new List <ObstaclePair>();
     for (int i = 0; i < m_Obstacles.Length; i++)
     {
         for (int j = 0; j < m_Obstacles[i].objectPoolAmount; j++)
         {
             GameObject   obstacle     = Instantiate(m_Obstacles[i].obstacleObject, m_ObjectPoolPosition);
             ObstaclePair obstaclePair = new ObstaclePair(obstacle, m_Obstacles[i]);
             m_ObjectPool.Add(obstaclePair);
         }
     }
 }
示例#3
0
 void ToObjectPool(ObstaclePair pair)
 {
     pair.obstacle.gameObject.transform.position = m_ObjectPoolPosition.position;
     pair.obstacle.gameObject.SetActive(false);
     m_ObjectPool.Add(pair);
 }