Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (newTransform)
        {
            Move();
        }


        //Detectem nodes on es desplaça el player i activem el desplaçament amb un doble "tap"
        if (doubleClick.doubleClickDone)
        {
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 100f))
            {
                if (moveEnded)
                {
                    place = hit.collider.GetComponent <DestinationPlace>();


                    if (place != null)
                    {
                        Debug.Log("place collider: " + hit.collider.name);

                        SetNewTransform(place);
                    }



                    if (hit.collider.tag == "Stairs")
                    {
                        timelineController.PlayFromTimelines(index);
                        index++;

                        if (index > 1)
                        {
                            index = 0;
                        }
                    }
                }
            }

            doubleClick.doubleClickDone = false;
        }

        //Usem dos dits per retornar a una posició


        if (Input.touchCount == 2)
        {
            if (Input.GetTouch(0).phase == TouchPhase.Began || Input.GetTouch(1).phase == TouchPhase.Began)
            {
                Debug.Log("Began");
                playerRotation.enabled = false;

                previousTouchDistance = Vector2.Distance(Input.GetTouch(0).position, Input.GetTouch(1).position);
                on = true;
            }
            else if (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved)
            {
                Debug.Log("Move");
                float   distance;
                Vector2 touch1 = Input.GetTouch(0).position;
                Vector2 touch2 = Input.GetTouch(1).position;
                distance      = Vector2.Distance(touch1, touch2);
                deltaDistance = previousTouchDistance - distance;

                if (deltaDistance > 40f && on)
                {
                    if (place.reachablePlaces.Count > 0)
                    {
                        if (place.tag == "GoBack")
                        {
                            place = place.reachablePlaces[0];
                        }
                        else
                        {
                            Debug.Log("No es diu GoBack");
                        }
                        // Debug.Log("Dos dits " + place);

                        SetNewTransform(place);
                        on = false;
                        allCanvas.SetActive(true);
                    }
                }
                return;
            }
            if (Input.GetTouch(0).phase == TouchPhase.Ended || Input.GetTouch(1).phase == TouchPhase.Ended)
            {
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 2f))
            {
                // Debug.Log("Interactuable amb " + hit.collider);
                Interactuable interactuable = hit.collider.GetComponentInChildren <Interactuable>();
                if (interactuable != null)
                {
                    interactuable.Interactua();
                }
            }
        }
    }