Ejemplo n.º 1
0
    void Update()
    {
        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.forward, out hit))
        {
            if (hit.collider.tag == "Button")
            {
                timer += Time.deltaTime;
                if (selected != hit.transform)
                {
                    selected      = hit.transform;
                    selectedScale = selected.localScale;
                }
                else
                {
                    float zoom = Mathf.PingPong(timer, zoomRange * zoomSpeed) / zoomSpeed;
                    selected.localScale = new Vector3(selectedScale.x * (1f + zoom), selectedScale.y * (1f + zoom), selectedScale.z * (1f + zoom));
                }
            }
            else if (hit.collider.tag == "Slider")
            {
                selected       = hit.transform;
                selectedScale  = selected.localScale;
                selectedSlider = selected.GetComponent <SliderScript>();
            }
            else if (selected)
            {
                unselectButton();
            }
        }
        if (Input.GetMouseButtonDown(0) && selected && selected.tag == "Button")
        {
            UnityEngine.UI.Button button;
            if ((button = selected.GetComponent <UnityEngine.UI.Button>()))
            {
                button.onClick.Invoke();
            }
        }
        if (Input.GetMouseButton(0) && selected && selected.tag == "Slider")
        {
            selectedSlider.updateSlider();
        }
    }