Ejemplo n.º 1
0
    void Update()
    {
#if UNITY_EDITOR
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            Debug.DrawRay(ray.origin, ray.direction);
            if (Physics.Raycast(ray, out hit, float.PositiveInfinity))
            {
                OnSelected.Dispatch(hit.collider.gameObject);
            }
        }
#else
        if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved)
        {
            // Get movement of the finger since last frame
            Touch      touch = Input.GetTouch(0);
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(touch.position);
            Debug.DrawRay(ray.origin, ray.direction);
            if (Physics.Raycast(ray, out hit, float.PositiveInfinity))
            {
                OnSelected.Dispatch(hit.collider.gameObject);
            }
        }
#endif
    }