// This assigns each dot a random color before it falls into place as well as its coordinate values.
    public void AssignDots(Transform Dot, int finalYPos)
    {
        int randomColor = 0;

        // Check if we should ignore a color for this particular dot assignment.
        if (shouldIgnoreColor)
        {
            randomColor = RandomColor(0, 5, colorToIgnore);
        }
        else
        {
            randomColor = Random.Range(0, 5);
        }

        // Store the Individual dot and renderer components in local variables.
        IndividualDot DotScript   = Dot.GetComponent <IndividualDot>();
        Renderer      DotRenderer = Dot.GetComponent <Renderer>();

        // Pick a random color.
        switch (randomColor)
        {
        case 0:
            DotScript.ThisDotsColor = IndividualDot.Color.Blue;
            DotRenderer.material    = Blue;
            break;

        case 1:
            DotScript.ThisDotsColor = IndividualDot.Color.Green;
            DotRenderer.material    = Green;
            break;

        case 2:
            DotScript.ThisDotsColor = IndividualDot.Color.Purple;
            DotRenderer.material    = Purple;
            break;

        case 3:
            DotScript.ThisDotsColor = IndividualDot.Color.Red;
            DotRenderer.material    = Red;
            break;

        case 4:
            DotScript.ThisDotsColor = IndividualDot.Color.Yellow;
            DotRenderer.material    = Yellow;
            break;
        }

        // Set the coordinates of each dot.
        DotScript.Coordinates.x = Dot.transform.position.x;
        DotScript.Coordinates.y = finalYPos;

        // Parent each dot to the game board.
        Dot.transform.SetParent(GameBoardParent);

        // Start the dots falling into place.
        StartCoroutine(DotScript.FallIntoPlace());
    }
Ejemplo n.º 2
0
    // This is called when we enter a new dot while drawing a line.
    public void AnotherDotEntered(Transform EnteredDot)
    {
        if (lineActive)
        {
            // Script references for the previous dot in the chain and the current one.
            IndividualDot PreviousDotScript = PreviousDot.GetComponent <IndividualDot>();
            IndividualDot EnteredDotScript  = EnteredDot.GetComponent <IndividualDot>();

            // Check if the dots are adjacent. No diagonal matching.
            if (Mathf.Abs(PreviousDotScript.Coordinates.x - EnteredDotScript.Coordinates.x) == 1 && Mathf.Abs(PreviousDotScript.Coordinates.y - EnteredDotScript.Coordinates.y) == 0 ||
                Mathf.Abs(PreviousDotScript.Coordinates.x - EnteredDotScript.Coordinates.x) == 0 && Mathf.Abs(PreviousDotScript.Coordinates.y - EnteredDotScript.Coordinates.y) == 1)
            {
                // Check if the dots are the same color.
                if ((int)EnteredDotScript.ThisDotsColor == (int)PreviousDotScript.ThisDotsColor)
                {
                    // If the new dot is a valid dot, we call a number of different actions for the new dot.
                    NewDotActions(EnteredDot);
                }
            }
        }
    }