Esempio n. 1
0
    private void OnTouchDown(Touch eventData)                           //This is called when we touch (or click) the screen thanks to the subscribed events above
    {
        Ray ray = mainCam.ScreenPointToRay(eventData.position);         //We define a ray into the camera from where we touched

        Debug.DrawRay(ray.origin, ray.direction * 100f, Color.red, 1f); //We debug the ray so we see it as a gizmo in the editor

        if (Physics.Raycast(ray, out RaycastHit hit))                   //Did the raycast hit something?
        {
            if (hit.transform.TryGetComponent(out Emoji throwable))     //If the hit object has the Enemy component we can safely store it to be thrown later
            {
                holding = throwable;
                holding.GrabMe(eventData.position);                     //We tell the grabbed object that we picked it up
            }
        }
    }