示例#1
0
 void RpcGiveSpeed(float speed)
 {
     if (faceRight && speed < 0)
     {
         controller2D.Flip();
         this.faceRight = false;
     }
     else if (!faceRight && speed > 0)
     {
         controller2D.Flip();
         this.faceRight = true;
     }
     animator.SetFloat("speed", Mathf.Abs(speed));
 }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        if ((controller.collisions.above || controller.collisions.below) && !controller.collisions.slidingDownMaxSlope)
        {
            velocity.y = 0;
        }

        Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));

        if (weapon != null)
        {
            weapon.ToggleOrEnable(gameObject, Input.GetButtonDown("Fire1_Erl"), Input.GetButton("Fire1_Erl"));
        }

        if (Input.GetButton("Jump_Erl") && controller.collisions.below && !controller.collisions.slidingDownMaxSlope)
        {
            Jump();
        }

        float targetVelocityX = input.x * moveSpeed;

        velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing,
                                      (controller.collisions.below) ? accelerationTimeGrounded : accelerationTimeAirborne);
        velocity.y += gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime, input);

        if (input.x > 0 && !controller.facingRight)
        {
            controller.Flip();
        }
        else if (input.x < 0 && controller.facingRight)
        {
            controller.Flip();
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            EffectOnDestroy.isSceneChange = true;
            SceneManager.LoadSceneAsync("Menu");
        }

        if (isExtending)
        {
            if (currentExtension >= jumpExtendHeight - .05f)
            {
                isExtending   = false;
                isContracting = true;
            }
            else
            {
                currentExtension             = Mathf.SmoothDamp(currentExtension, jumpExtendHeight, ref jumpSmoothing, jumpAnimationLength);
                body.transform.localPosition = Vector3.up * currentExtension;
            }
        }
        else if (isContracting)
        {
            if (currentExtension <= 0)
            {
                isContracting = false;
            }
            else
            {
                currentExtension             = Mathf.SmoothDamp(currentExtension, 0, ref jumpSmoothing, jumpAnimationLength * 3);
                body.transform.localPosition = Vector3.up * currentExtension;
            }
        }

        if (Mathf.Abs(transform.position.x - lastX) > soundXDiff)
        {
            //sounds.PlaySound (9);
            lastX += Mathf.Sign(transform.position.x - lastX) * soundXDiff;
        }
    }