Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;

        if (Physics.Raycast(ray, out hitInfo))
        {
            Tile hitTile = hitInfo.collider.GetComponentInParent <Tile>();
            HoverTile(hitTile); //Set current tile as hovered tile.
        }
        else
        {
            //myHoveredIndicator.disableSelection();
            ClearSelection();
        }

        if (Input.GetMouseButtonDown(0))
        {
            if (hoveredTile != null)
            {
                UnitCheck = hoveredTile.GetComponentInChildren <Unit>();
                if (UnitCheck != null)
                {
                    temp        = UnitCheck.GetComponentInChildren <PlayerOwned>();
                    checkPlayer = temp.owner;
                    if (checkPlayer == currentPlayer)
                    {
                        selectedTile = hoveredTile;
                        SelectObject(selectedTile);
                        mySelectedIndicator.activateSelection();
                    }
                }


                if (UnitCheck == null || (checkPlayer == currentPlayer))
                {
                    selectedTile = hoveredTile;
                    SelectObject(selectedTile);
                    mySelectedIndicator.activateSelection();
                }
            }
        }
        if (Input.GetMouseButtonUp(1))
        {
            UnitCheck.MoveNextTile();
        }
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            selectedTile = null;
            mySelectedIndicator.disableSelection();
        }
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            UnitCheck.MoveNextTile();
        }
    }
Ejemplo n.º 2
0
    void SelectObject(Tile obj)
    {
        if (hoveredTile != null)
        {
            if (obj == hoveredTile)
            {
                myHoveredIndicator.activateSelection();
                return;
            }

            ClearSelection();
        }
        selectedTile = obj;
    }