Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (timeBeforeNextArrow > 0)
        {
            timeBeforeNextArrow -= Time.deltaTime;
        }
        if (timeBeforeNextInvincibility > 0)
        {
            timeBeforeNextInvincibility -= Time.deltaTime;
        }
        if (timeBeforeNextAoe > 0)
        {
            timeBeforeNextAoe -= Time.deltaTime;
        }

        if (dead)
        {
            return;
        }

        insideAoeDuration -= Time.deltaTime * aoeHealSpeed;
        if (insideAoeDuration < 0)
        {
            insideAoeDuration = 0;
        }

        if (invincibilityRemaining > 0)
        {
            invincibilityRemaining -= Time.deltaTime;
            if (invincibilityRemaining <= 0)
            {
                EndInvincibility();
            }
        }

        if (aoeRemaining > 0)
        {
            aoeRemaining -= Time.deltaTime;
            if (aoeRemaining <= 0)
            {
                EndAoe();
            }
        }

        var horizontal = Input.GetAxis("Horizontal");
        var vertical   = Input.GetAxis("Vertical");

        Vector2 move = decision.GetMove().normalized *Math.Max(Math.Abs(horizontal), Math.Abs(vertical)) * speed * Time.deltaTime;

        gameObject.transform.Translate(move.x, move.y, 0);

        if (move != Vector2.zero)
        {
            rotationObject.transform.eulerAngles = (Vector3.forward * Vector2.SignedAngle(Vector2.up, move));
        }
        if (decision.IsShooting() && timeBeforeNextArrow <= 0)
        {
            ShootArrow();
        }
        if (decision.IsStartingInvincibility() && timeBeforeNextInvincibility <= 0)
        {
            StartInvincibility();
        }
        if (decision.IsStartingAoe() && timeBeforeNextAoe <= 0)
        {
            StartAoe();
        }
    }