Exemplo n.º 1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        UpdateBoostCanvas();
        if (player.dead)
        {
            player.aimCircle.position = nullPos;
            drawLine.DrawALine(nullPos, nullPos);
            return;
        }
        UpdateEnergy();

        UpdateBehavior();
        if (player.playerStunned)
        {
            player.aimCircle.position = nullPos;
            drawLine.DrawALine(nullPos, nullPos);
            return;
        }

        if (!grabbedEnemy)
        {
            drawLine.DrawALine(nullPos, nullPos);
            closestEnemy = null;
            if (player.enemiesInAngle.Count > 0)
            {
                closestEnemy = player.enemiesInAngle.OrderByDescending(e => Vector3.Distance(e.GetCurrentPosition(), transform.position)).Reverse().First();
            }
        }
        else
        {
            if (!player.enemiesInAngle.Contains(closestEnemy))
            {
                if (Vector3.Distance(closestEnemy.transform.position, transform.position) > 3)
                {
                    closestEnemy.isDead = false;
                    closestEnemy        = null;
                    grabbedEnemy        = false;
                    return;
                }
            }
            drawLine.DrawALine(tongueTransform.position, closestEnemy.transform.position);
        }
        if (Input.GetButton("Fire1"))
        {
            if (closestEnemy && !closestEnemy.isDead)
            {
                if (!snackCooldown)
                {
                    closestEnemy.isDead = true;
                    grabbedEnemy        = true;
                    snackCooldown       = true;
                    StartCoroutine(SnackingCooldown());
                    SoundManager.singleton.TongueWhipSound();
                }
            }
        }
        if (grabbedEnemy)
        {
            closestEnemy.rig.velocity = (transform.position - closestEnemy.transform.position).normalized * 300 * Time.deltaTime;
            closestEnemy.rig.mass     = 0.1f;
        }
        if (closestEnemy == null)
        {
            player.aimCircle.position = nullPos;
        }
        else
        {
            player.aimCircle.position = closestEnemy.transform.position;
        }

        UpdateMovement();
        ClampVelocity();
    }