Beispiel #1
0
    void RaycastTiles()
    {
        RaycastHit tileHit;
        Ray        screenRay = myCamera.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(screenRay, out tileHit))
        {
            if (tileHit.collider.CompareTag("Tile"))
            {
                WorldTile newTile = tileHit.collider.GetComponentInParent <WorldTile>();
                if (newTile != selected)
                {
                    if (selected != null)
                    {
                        selected.Deselect();
                    }
                    selected = newTile;
                    selected.Select();
                }
                if (Input.GetMouseButtonDown(0)) //Change this to use virtual buttons later
                {
                    if (lastClicked != null)
                    {
                        try
                        {
                            lastClicked.UnClick();
                        }
                        catch { }
                    }
                    lastClicked = selected;
                    selected.Click();
                }
            }
            else
            {
                ClearSelection();
            }
        }
        else
        {
            ClearSelection();
        }
    }