private void DetectFingerInPhone() { if (Input.touchCount == 0) { if (currentPetting) { currentPetting.OnTouchUp(); } currentPetting = null; return; } Ray ray; RaycastHit hit; Vector3 touchPosition = Input.GetTouch(0).position; // First down if (Input.GetTouch(0).phase == TouchPhase.Began) { ray = mainCamera.ScreenPointToRay(touchPosition); if (Physics.Raycast(ray, out hit, 50f, sleep)) { Debug.Log("petpet1"); petting pet = hit.rigidbody.GetComponent <petting>(); if (pet) { currentPetting = pet; currentPetting.OnTouchDown(); } } } }
private void DetectFingerInEditor() { Ray ray; RaycastHit hit; // First down if (Input.GetMouseButtonDown(0)) { ray = mainCamera.ScreenPointToRay(Input.mousePosition); // if (Physics.Raycast(ray, out hit, 50f, interactableLayer)) // { // // maybe hit an interactable // Interactable interactable = hit.rigidbody.GetComponent<Interactable>(); // if (interactable) // { // // really hit an interactable // currentInteractable = interactable; // startInteractDistance = hit.distance; // // Inform interactable with the touch posisiont // startTouchPosition = mainCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, startInteractDistance)); // currentInteractable.OnTouchDown(startTouchPosition); // } // } //animal disappear // if (Physics.Raycast(ray, out hit, 50f, animalLayer)){ // Feed feed = hit.rigidbody.GetComponent<Feed>(); // if(feed){ // currentFeed = feed; // currentFeed.OnTouchDown(); // } // } //animal petting if (Physics.Raycast(ray, out hit, 50f, sleep)) { Debug.Log("petpet1"); petting pet = hit.rigidbody.GetComponent <petting>(); if (pet) { currentPetting = pet; currentPetting.OnTouchDown(); } } } else if (Input.GetMouseButtonUp(0)) { // //Reset if (currentPetting) { currentPetting.OnTouchUp(); } currentPetting = null; } }