Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1) && GameManager.instance.buildHouseButton.interactable)
        {
            OnBuildHouseClicked();
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2) && GameManager.instance.buildPowerplantButton.interactable)
        {
            OnBuildPowerplantClicked();
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3) && GameManager.instance.buildWallButton.interactable)
        {
            OnBuildWallClicked();
        }
        else if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            OnDemolishClicked();
        }

        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out RaycastHit hit, float.MaxValue, GameManager.instance.buildingLayer.value))
        {
            DestructableObject DO = hit.collider.gameObject.GetComponent <DestructableObject>();
            if (prevHighlighted != DO)
            {
                DO.Highlight();
                if (prevHighlighted != null)
                {
                    prevHighlighted.DeHighlight();
                }
                prevHighlighted = DO;
            }
        }