Example #1
0
    void Update()
    {
        // -- allows for animation cancelling when load animation accidentely triggered on first frame
        // -- before crosshair is touched
        if (gun.isMovingCrosshair)
        {
            animator.SetBool("isLoading", false);

            if (curArrowController.getLoaded())
            {
                curArrowController.PutBackAnimation();
            }
        }

        // -- reloading
        curReloadTime -= Time.deltaTime;

        if (reload && curReloadTime < 0f)
        {
            AddNewArrow();

            reload = false;
        }

        // -- getting touch input
        if (Input.touchCount > 0)
        {
            touch = Input.GetTouch(0);

            // -- if reloaded and not on crosshair
            if (curReloadTime < 0f && !gun.isMovingCrosshair)
            {
                if (touch.phase == TouchPhase.Began)
                {
                    DragStart();

                    // -- animation
                    curArrowController.LoadAnimation();
                    animator.SetBool("isReleasing", false);
                    animator.SetBool("isLoading", true);
                }

                if (touch.phase == TouchPhase.Moved)
                {
                    Dragging();
                }

                if (touch.phase == TouchPhase.Ended)
                {
                    DragRelease();

                    // -- animation
                    animator.SetBool("isLoading", false);
                    animator.SetBool("isReleasing", true);
                }
            }
        }
    }