Example #1
0
    void spawnCompound()
    {
        currentCompound = new CompoundObstacle();
        int count = Random.Range(2, 5);

        for (int i = 0; i < count; i++)
        {
            Vector3 pos = new Vector3(
                9 + Random.Range(0, 6),
                Random.Range(-4, 4),
                -2
                );
            bool posOK          = true;
            ComponentObstacle c = (ComponentObstacle)Instantiate(componentPrefab, pos, Quaternion.identity);
            if (c.GetComponent <Collider2D> ().OverlapCollider(contactFilter, res) > 0)
            {
                Destroy(c.gameObject);
                posOK = false;
            }
            if (posOK)
            {
                currentCompound.addComponent(c);
            }
        }
        if (currentCompound.getComponentCount() == 0)
        {
            currentCompound = null;
        }
        else
        {
            componentCountLabel.text = currentCompound.getComponentCount() + " component(s)";
        }
    }
Example #2
0
 void destroyCompound()
 {
     if (currentCompound != null)
     {
         currentCompound.despawn();
         currentCompound          = null;
         componentCountLabel.text = "No components";
     }
 }