예제 #1
0
    /// <summary>
    /// Call this to snap the end of a flight path to an opened honeycomb. This method would
    /// only perform the snapping if there is an opened honeycomb that is close enough.
    /// </summary>
    /// <param name="path">Flight path for a given bee.</param>
    public void SnapToHoneycomb(FlightPath path)
    {
        // Get the end point of the path.
        Vector2 current = path.GetLastPosition();

        // Go through and find an open honeycomb that is close by the end point.
        foreach (GameObject honeycombObject in openHoneycombs)
        {
            Vector2 testPos = honeycombObject.transform.position;
            if (Vector2.Distance(current, testPos) < honeycombSize * 0.55f)
            {
                Honeycomb honeycomb = honeycombObject.GetComponent <Honeycomb>();

                // Snap the path to the honeycomb.
                path.ConnectToHoneycomb(honeycomb);

                // Register this path with the honeycomb, this is so that we can update
                // the path's color if the honeycomb is closed before the bee reaches it.
                honeycomb.RegisterPath(path);
                break;
            }
        }
    }