Ejemplo n.º 1
0
    //Simple raycast to mouse position
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, raycastDistance))
            {
                //Deselect previous selection
                if (lastInstance)
                {
                    DeselectPrevious(lastInstance);
                }

                //Obtain component - in the demo scene, selecting residential or commercial classes act the same
                Houses house = hit.transform.GetComponent <Houses>();

                if (house != null && !cameraBlur.enabled)
                {
                    if (house.GetType() == typeof(Residential))
                    {
                        Select(house, clickSound);
                    }
                }
            }
        }

        //Adjust blur effect runtime based on whether GUI's being displayed or not
        if (houseImage.enabled && !cameraBlur.enabled)
        {
            cameraBlur.enabled = true;
        }
        else if (!houseImage.enabled && cameraBlur.enabled)
        {
            cameraBlur.enabled = false;
        }

        //Deselect previous selection on right mouse click
        if (Input.GetMouseButtonDown(1))
        {
            DeselectPrevious(lastInstance);
        }
    }