我有一个动作脚本,当我向右移动时,它是好的,但当我向右移动时,它会结巴。我试过了,没有摄像机移动同样的问题。我只是不明白为什么。这两个方向的代码是相同的。
这是它从其他脚本中获取变量的代码,但是除了变量,它们没有任何其他代码。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InputManager : MonoBehaviour
{
Rigidbody2D rb;
float jumpForce;
float downForce;
float speed;
float maxSpeed;
float maxJumps;
float currentJumps;
float cutJumpHeight;
float jumpBufferTimer;
float jumpBuffer;
float jumpRememberTimer;
float jumpRemember;
float x;
float y;
bool isGrounded = false;
AudioSource jumpSound;
Jump jumpScript;
Movement movementScript;
GameObject[] groundCheckPoints;
void Start()
{
jumpScript = GetComponent<Jump>();
movementScript = GetComponent<Movement>();
rb = GetComponent<Rigidbody2D>();
groundCheckPoints = GameObject.FindGameObjectsWithTag("Check Point");
}
void Update()
{
MyInput();
IsGrounded();
FlipCharacter();
jumpForce = jumpScript.jumpForce;
speed = movementScript.speed;
maxJumps = jumpScript.maxJumps;
cutJumpHeight = jumpScript.cutJumpHeight;
jumpRemember = jumpScript.jumpRememberTime;
jumpBuffer = jumpScript.jumpBufferTime;
jumpSound = jumpScript.jumpSound;
}
void FlipCharacter()
{
if (x > 0)
{
transform.rotation = Quaternion.Euler(0, 0, 0);
}else if(x < 0)
{
transform.rotation = Quaternion.Euler(0, 180, 0);
}
}
void IsGrounded()
{
for (int i = 0; i < groundCheckPoints.Length; i++)
{
isGrounded = Physics2D.OverlapCircle(groundCheckPoints[i].transform.position, 0.1f, LayerMask.GetMask("Ground"));
if (isGrounded)
{
break;
}
}
Jump();
}
void FixedUpdate()
{
MovementPlatformer();
}
void MyInput()
{
x = Input.GetAxisRaw("Horizontal");
y = Input.GetAxisRaw("Vertical");
}
void Jump()
{
jumpBufferTimer -= Time.deltaTime;
jumpRememberTimer -= Time.deltaTime;
if (isGrounded)
{
currentJumps = maxJumps;
}
if (currentJumps > 0)
{
jumpBufferTimer = jumpBuffer;
}
if (Input.GetKeyDown(KeyCode.Space))
{
jumpRememberTimer = jumpRemember;
}
if (jumpBufferTimer > 0 && jumpRememberTimer > 0)
{
jumpBufferTimer = 0;
jumpRememberTimer = 0;
jumpSound.Play();
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
currentJumps--;
}
if (Input.GetKeyUp(KeyCode.Space) && rb.velocity.y > 0)
{
rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * cutJumpHeight);
}
}
void MovementPlatformer()
{
rb.velocity = new Vector2(speed * x, rb.velocity.y);
}
}发布于 2022-06-19 08:26:34
这与翻转字符函数有关,当我将它移动到固定的,更新它,修复它。
https://stackoverflow.com/questions/72591521
复制相似问题