Guy.Update C# (CSharp) Метод

Update() приватный Метод

private Update ( ) : void
Результат void
    void Update()
    {
        var device = InputCoalescer.Players[PlayerId];

        if (!IsAttached && BodyRB.position.y > baseHeight + 2.5f && !DontConnect)
        {
            AboveGround = true;
            BodyRB.AddForce(Mathf.Sign(BodyRB.velocity.x + 0.00001f) * 4.0f, 1.5f, 0, ForceMode.Force);
            sincePushedUp += Time.deltaTime;
            if (sincePushedUp > 2)
            {
                BodyRB.AddForce(Mathf.Sign(BodyRB.velocity.x + 0.00001f) * 10.0f, 500.0f, 0, ForceMode.Force);
                BodyRB.velocity = new Vector3(-1 * BodyRB.velocity.x, BodyRB.velocity.y, BodyRB.velocity.z);
                sincePushedUp -= 2;
            }
        }
        else
            AboveGround = false;

        if (ShouldWalk && IsAttached)
        {
            if (device.MovingRight && activeCoroutineDirection != 1)
            {
                LastWalkSign = 1.0f;
                var token = new Object();
                activeCoroutineDirection = 1;
                activeCoroutine = token;
                StartCoroutine(LiftLeg(token, 1));
            }

            if (device.MovingLeft && activeCoroutineDirection != -1)
            {
                LastWalkSign = -1.0f;
                var token = new Object();
                activeCoroutineDirection = -1;
                activeCoroutine = token;
                StartCoroutine(LiftLeg(token, -1));
            }

            if (!device.MovingLeft && !device.MovingRight)
            {
                if (LastWalkSign != 0 && activeCo2 == null)
                {
                    var token = new Object();
                    StartCoroutine(ResetWalkSign(token));
                    activeCo2 = token;
                }
                activeCoroutineDirection = 0;
                activeCoroutine = null;
                stabilize = true;
            }

            movementForce = device.MovementSpeed;
        //            if (movementForce != 0)
        //                Debug.Log("Movement force = " + movementForce);
        }

        var target = BodyRB.rotation.z;
        BodyRB.AddTorque(0, 0, uprightStrength * -target * (IsAttached ? 500 : 100));

        if (stabilize && uprightStrength == 1)
        {
            target = RightLegRB.rotation.z;
            RightLegRB.AddTorque(0, 0, -target * 50);
            target = LeftLegRB.rotation.z;
            LeftLegRB.AddTorque(0, 0, -target * 50);
        }

        if (device.DetachPressed && Application.loadedLevelName != "Title")
        {
            foreach (var hinge in transform.parent.GetComponentsInChildren<HingeJoint>())
            {
                if (!hinge.useLimits || Input.GetKey(KeyCode.LeftShift))
                    hinge.breakForce = 0.00001f;
            }

            // safe guard : check for guys overlapping other guys and respawn them
            foreach (var g in Globals.Guys[PlayerId])
            {
                foreach (var gg in Globals.Guys[PlayerId])
                {
                    if (g != gg && g.BodyRB.collider.bounds.Intersects(gg.BodyRB.collider.bounds))
                    {
                        // reset both
                        var delta = (g.BodyRB.transform.position - gg.BodyRB.transform.position) * 10.0f;
                        foreach (var rb in g.transform.parent.GetComponentsInChildren<Rigidbody>())
                            rb.transform.position -= delta;
                    }
                }
            }

            MainGuys[PlayerId].ShouldWalk = true;
            MainGuys[PlayerId].IsAttached = true;

            if (TotalAttachedGuys != null)
            {
                TotalAttachedGuys.Clear();
                TotalAttachedGuys.Add(MainGuys[PlayerId]);
            }
        }
    }