Exemple #1
0
    private void FixedUpdate()
    {
        if (inTutorial)
        {
            return;
        }

        if (!insidePortal)
        {
            // Doing any input
            if (isTouching && mainLogic.getShots() > 0)
            {
                var dragOffset = Camera.main.ScreenToWorldPoint(touchB) - Camera.main.ScreenToWorldPoint(touchA);

                aimDir = dragOffset.normalized;

                wasTouchingLastFixed = true;
            }
            else
            {
                // released after drag
                if (wasTouchingLastFixed && mainLogic.getShots() > 0)
                {
                    float dragDist = Vector2.Distance(Camera.main.ScreenToWorldPoint(touchB), Camera.main.ScreenToWorldPoint(touchA));
                    dragDist = Mathf.Clamp(dragDist, dragDistMinMax.x, dragDistMinMax.y);

                    // didn't drag far enough, reset shot
                    if (dragDist <= dragReleaseDist)
                    {
                        hideDragIndicationInstant();
                    }
                    else // do a shot
                    {
                        rb.velocity          = rb.velocity * keptVelocityOnShot;
                        rb.gravityScale      = 1;
                        wasTouchingLastFixed = false;
                        rb.AddForce(-aimDir * shootStrength, ForceMode2D.Impulse);

                        mainLogic.didShot();

                        visuals.deathDustFX((Vector2)transform.position /* + aimDir*/);

                        // Doesnt feel right
                        //if(shootStrength == shootStrMinMax.y)
                        //    FindObjectOfType<HitStop>().Stop(0.025f);

                        StartCoroutine(hideDragIndication());
                    }

                    canRelease = false;
                }
            }
        }
    }