示例#1
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "ShotBubble")
     {
         ShotBubble b = other.gameObject.GetComponent <ShotBubble>();
         grid.AddBubble(this, b);
     }
 }
示例#2
0
    public void AddBubble(Bubble collisionBubble, ShotBubble shotBubble)
    {
        List <Bubble> neighbors   = BubbleEmptyNeighbors(collisionBubble);
        float         minDistance = 10000.0f;
        Bubble        newBubble   = null;

        //Here I find the right position to place the shot bubble in the grid and also check for matches in neghbor bubbles
        foreach (Bubble n in neighbors)
        {
            float d = Vector2.Distance(n.transform.position, shotBubble.transform.position);
            if (d < minDistance)
            {
                minDistance = d;
                newBubble   = n;
            }
        }
        shotBubble.gameObject.SetActive(false);
        newBubble.SetType(shotBubble.type);
        newBubble.gameObject.SetActive(true);

        CheckMatchesForBubble(newBubble);
    }