// Update is called once per frame
 void Update()
 {
     if (isActive)
     {
         persistTimeDelta -= Time.deltaTime;
         if (persistTimeDelta <= 0f)
         {
             Destroy(gameObject);
             isActive         = false;
             persistTimeDelta = 3f;
         }
         // Handle Mr Stuntman rotation for wind direction
         if (gameObject.name.Contains("Left"))
         {
             mrStuntman.NegativeRotation(Vector3.back * rotationMultiplier);
         }
         else
         {
             mrStuntman.PositiveRotation(Vector3.forward * rotationMultiplier);
         }
     }
 }
Exemple #2
0
    void HandleTouchInput()
    {
        if (!isPaused)
        {
            // Mouse & keyboard controls
            if (Input.touchCount == 0)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    if (Input.mousePosition.x < Screen.width / 2)
                    {
                        // Left Click
                        mrStuntman.PositiveRotation();
                    }
                    else if (Input.mousePosition.x > Screen.width / 2)
                    {
                        // Right Click
                        mrStuntman.NegativeRotation();
                    }
                }

                if (Input.GetKeyDown("space"))
                {
                    mrStuntman.Jump();
                }
                else if (Input.GetKeyDown("d"))
                {
                    mrStuntman.Duck();
                }
            }
            else
            {
                // Get the single touch
                Touch touch = Input.GetTouch(0);
                if (touch.phase == TouchPhase.Began)
                {
                    touchStartPos = touch.position;
                    touchEndPos   = touch.position;
                }
                // Update the end position based on where the touch is after Update
                else if (touch.phase == TouchPhase.Moved)
                {
                    touchEndPos = touch.position;
                }
                // End of touch
                else if (touch.phase == TouchPhase.Ended)
                {
                    touchEndPos = touch.position;

                    // Check if drag distance is greater than 20% of the screen height
                    if (Mathf.Abs(touchEndPos.x - touchStartPos.x) > dragThreshold || Mathf.Abs(touchEndPos.y - touchStartPos.y) > dragThreshold)
                    {
                        if (touchEndPos.y > touchStartPos.y)
                        {
                            mrStuntman.Jump();
                        }
                        else
                        {
                            mrStuntman.Duck();
                        }
                    }
                    // Input is a tap
                    else
                    {
                        if (touchEndPos.x < Screen.width / 2)
                        {
                            mrStuntman.PositiveRotation();
                        }
                        else
                        {
                            mrStuntman.NegativeRotation();
                        }
                    }
                }
            }
        }
    }