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;
        }
    }
Exemple #3
0
    public void touch()
    {
        ChatText.text += main_script.my_name;
        ChatText.text += "很享受撫摸\n";
        GameObject pet_obj    = GameObject.Find("/UI/Button/撫摸");
        petting    pet_script = pet_obj.GetComponent <petting>();

        pet_script.nowHP += 20;

        GameObject          src_obj    = GameObject.Find("Pet");
        pet_controll_script src_script = src_obj.GetComponent <pet_controll_script>();

        src_script.check_ac();
        ++src_script.cnt;
    }