コード例 #1
0
ファイル: MouseManager.cs プロジェクト: vasilhsbel/GD-GTO4
    // 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();
        }
    }
コード例 #2
0
ファイル: MouseManager.cs プロジェクト: vasilhsbel/GD-GTO4
    void ClearSelection()
    {
        if (hoveredTile == null)
        {
            myHoveredIndicator.disableSelection();
            return;
        }

        if (selectedTile == null)
        {
            return;
        }

        hoveredTile = null;
    }