Beispiel #1
0
    IEnumerator ShakeCameraOnSecondAttack()
    {
        Camera  camera           = Camera.main;
        Vector3 startingPosition = camera.transform.localPosition;

        float timePassed = 0;
        float x          = 0;

        if (player.isFacingLeft)
        {
            direction = -1;
        }
        else
        {
            direction = 1;
        }
        while (timePassed < timeToShakeForAttack)
        {
            Vector2 deltaPosition = new Vector2(EasingFunction.EaseOutCirc(0.01f, 0.7f, x) * direction,
                                                EasingFunction.EaseInBack(0.01f, 0.4f, x));

            camera.transform.localPosition = startingPosition + (Vector3)deltaPosition;

            float maxTime   = maxTimeBetweenShakesAttack * Time.deltaTime;
            float sleepTime = Random.Range(0, maxTime);
            yield return(new WaitForSeconds(sleepTime));

            timePassed += Time.deltaTime;
            x          += Time.fixedDeltaTime * 2.1f;
        }
        camera.transform.localPosition = startingPosition;
    }