Exemplo n.º 1
0
        void Update()
        {
            this.AddGravity();
            this.UnderWaterProccess();

            var oldIsGrouded = this.characterController.isGrounded;

            this.characterController.move(this.velocity);

            var isGrounded = this.characterController.isGrounded;

            if (!oldIsGrouded && isGrounded)
            {
                this.velocityByGravity.x = 0.0f;
            }

            if (!isGrounded && this.velocity.y < 0.0f)
            {
                this.brokableObject?.Broker.Publish(Fall.Get());
            }

            if (this.canPublishLanded)
            {
                if (isGrounded)
                {
                    this.brokableObject?.Broker.Publish(Landed.Get());
                    this.canPublishLanded = false;
                }
            }
            else
            {
                if (!isGrounded)
                {
                    this.canPublishLanded = true;
                }
            }

            if (isGrounded)
            {
                this.velocityByGravity.y = 0.0f;
            }
            if (this.characterController.collisionState.above)
            {
                this.velocityByGravity.y = 0.0f;
            }

            if (this.velocity.x == 0.0f)
            {
                this.brokableObject?.Broker.Publish(Idle.Get());
            }
            else
            {
                this.brokableObject?.Broker.Publish(Move.Get(this.velocity));
            }
            this.velocity = Vector2.zero;
        }