Пример #1
0
    private IEnumerator TrackButtonPress(String buttonName, PickupController.Slot slot, Vector2 startPos, float startTime)
    {
        bool isDrag = false;

        pickups.TouchPickup(slot);

        //Wait for the button to be released
        while (CrossPlatformInputManager.GetButton(buttonName))
        {
            //If the button is not released within the threshold time then this touch is treated as a drag
            if (allowDraggingPickups)
            {
                if (!isDrag && Time.time - startTime > pickupTimeThreshold)
                {
                    isDrag = true;
                    pickups.StartDragging(slot, CrossPlatformInputManager.GetLastKnownPos(buttonName));
                }
                if (isDrag)
                {
                    pickups.Drag(CrossPlatformInputManager.GetLastKnownPos(buttonName));
                }
            }
            yield return(new WaitForFixedUpdate());
        }
        if (!isDrag)
        {
            pickups.UsePickup(slot);
        }
        else
        {
            pickups.EndDrag();
        }
    }
Пример #2
0
    private void Update()
    {
        //reset previous frame values
        move       = Vector3.zero;
        brakeForce = 0;

        // Get the axis input.
        float v = CrossPlatformInputManager.GetAxis("Vertical");

        //Accelerate if axis is pushed forward
        if (v > 0)
        {
            // calculate camera relative direction to move:
            Vector3 camForward = Vector3.Scale(cam.forward, new Vector3(1, 0, 1)).normalized;
            move = v * camForward;
        }
        //Brake if axis is pulled back
        else
        {
            brakeForce = Mathf.Abs(v);
        }

        //prevent buttons firing in pause menu, etc.
        if (Time.timeScale == 1f)
        {
            //If we detect a touch then start tracking it
            if (CrossPlatformInputManager.GetButtonDown("Right"))
            {
                StartCoroutine(TrackButtonPress("Right", PickupController.Slot.RIGHT, CrossPlatformInputManager.GetLastKnownPos("Right"), Time.time));
            }
            if (CrossPlatformInputManager.GetButtonDown("Left"))
            {
                StartCoroutine(TrackButtonPress("Left", PickupController.Slot.LEFT, CrossPlatformInputManager.GetLastKnownPos("Left"), Time.time));
            }

            //If we detect a shake then trigger the response
            if (CrossPlatformInputManager.GetButtonDown("Shake"))
            {
                transforms.RemoveCurrent();
            }
        }
    }