Example #1
0
    // after the swap check if there any match, if not, swap it back
    IEnumerator SmoothSwap(TileBehaviorVer3 prev)
    {
        // swap
        Vector3 targetPos  = prev.transform.position;
        Vector3 currentPos = transform.position;

        for (float t = 0f; t <= 1; t += 0.1f)
        {
            float lerpAmount = Mathf.SmoothStep(0, 1, t);
            prev.gameObject.transform.position = Vector3.Lerp(targetPos, currentPos, lerpAmount);
            transform.position = Vector3.Lerp(currentPos, targetPos, lerpAmount);
            yield return(null);
        }

        prev.gameObject.transform.position = currentPos;
        transform.position = targetPos;

        // tell GridMangager its swap
        GridManagerVer3.instance.tile[Mathf.RoundToInt(targetPos.x), Mathf.RoundToInt(targetPos.y)]   = this;
        GridManagerVer3.instance.tile[Mathf.RoundToInt(currentPos.x), Mathf.RoundToInt(currentPos.y)] = prev;

        // GridManager check if there's a match in the grid
        GridManagerVer3.instance.CheckGrid();

        // if not, swap them back
        if (!GridManagerVer3.instance.hasMatch)
        {
            for (float t = 0f; t <= 1; t += 0.1f)
            {
                float lerpAmount = Mathf.SmoothStep(0, 1, t);
                prev.transform.position = Vector3.Lerp(currentPos, targetPos, lerpAmount);
                transform.position      = Vector3.Lerp(targetPos, currentPos, lerpAmount);
                yield return(null);
            }

            prev.gameObject.transform.position = targetPos;
            transform.position = currentPos;

            GridManagerVer3.instance.tile[Mathf.RoundToInt(targetPos.x), Mathf.RoundToInt(targetPos.y)]   = prev;
            GridManagerVer3.instance.tile[Mathf.RoundToInt(currentPos.x), Mathf.RoundToInt(currentPos.y)] = this;
        }
    }
Example #2
0
 private void Deselect()
 {
     isSelected   = false;
     rend.color   = Color.white;
     prevSelected = null;
 }
Example #3
0
 private void Select()
 {
     isSelected   = true;
     rend.color   = selectedColor;
     prevSelected = this;
 }