Esempio n. 1
0
    void OnMouseDown()
    {
        if (render.sprite == null || BoardController.instance.IsShifting)
        {
            return;
        }

        if (isSelected)
        {
            Deselect();
        }
        else
        {
            if (previousSelected == null)
            {
                Select();
            }
            else
            {
                //swap sprites only if rhem adjoined
                if (GetAllAdjoinedTiles().Contains(previousSelected.gameObject))
                {
                    cleared = false;
                    SwapSprite(previousSelected.render);
                    previousSelectedTemp = previousSelected;
                    previousSelected.Deselect();
                    ClearAllMatches();

                    //find all matches on board
                    StopCoroutine(BoardController.instance.FindMatchesOnBoard());
                    StartCoroutine(BoardController.instance.FindMatchesOnBoard());

                    //cancel swap if matching isn't found
                    if (!cleared)
                    {
                        SwapSprite(previousSelectedTemp.GetComponent <SpriteRenderer>());
                        previousSelectedTemp = null;
                        cleared = false;
                    }
                }
                else
                {
                    previousSelected.GetComponent <ElementController>().Deselect();
                    Select();
                }
            }
        }
    }
Esempio n. 2
0
    private List <GameObject> FindMatch(Vector2 castDir, ElementController gameObject)
    {
        List <GameObject> matchingTiles = new List <GameObject>();
        RaycastHit2D      hit           = Physics2D.Raycast(transform.position, castDir);

        while (hit.collider != null && hit.collider.GetComponent <SpriteRenderer>().sprite == gameObject.GetComponent <SpriteRenderer>().sprite)
        {
            matchingTiles.Add(hit.collider.gameObject);
            hit = Physics2D.Raycast(hit.collider.transform.position, castDir);
        }
        return(matchingTiles);
    }