Exemplo n.º 1
0
    private List <GameObject> highlightedPath = new List <GameObject>(); // stores the highlighted tiles

    public void ShowPath(int mov)
    {
        // creates tiles to show path selected by the player
        mov++;

        Vector3 hoverPos = mousePosition.GetAimedPosition();

        hoverPos.y = mousePosition.mouvementTilePrefab.transform.position.y;
        if (mousePosition.IsValidVector(hoverPos))
        {
            // if a transform is same position is in the array : remove all tile after that transform index
            RemoveCheck(hoverPos);
            // if the tile position isn't in the array and still path.range <= mov : add it to the path

            // path.Count never equal to 0 because it always contains gameobject's own position
            //Debug.Log(path.Count);
            if (highlightedPath.Count == 0)
            {
                // add the tile the player is on
                //Debug.Log("Empty");
                highlightedPath.Add(Instantiate(mousePosition.mouvementTilePrefab, new Vector3(gameObject.transform.position.x, mousePosition.mouvementTilePrefab.transform.position.y, gameObject.transform.position.z), Quaternion.identity)); // path was empty
            }
            if (highlightedPath[highlightedPath.Count - 1].transform.position == hoverPos)                                                                                                                                                       // cursor still on the same tile
            {
                //Debug.Log("Same pos");
            }
            if (highlightedPath.Count < mov && !IsInPath(hoverPos) && OneUnitDist(hoverPos)) // creates a continuous path
            {
                //Debug.Log("New pos");
                highlightedPath.Add(Instantiate(mousePosition.mouvementTilePrefab, hoverPos, Quaternion.identity)); // path is empty
            }
        }
    }