答案 0 :(得分:0)
我通过重构捕获逻辑(如代码下)解决了它。
原样。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] private float movementSpeed = 5.0f;
[SerializeField] private bool isGrounded = false;
private Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
move();
jump();
}
private void move()
{
float move = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(movementSpeed * move * Time.deltaTime, rb.velocity.y);
}
private void jump()
{
if(Input.GetKeyDown(KeyCode.Space) && isGrounded == true)
{
Debug.Log("jump");
}
}
void OnCollisionStay2D(Collision2D, col)
{
if(col.gameObject.tag == "Ground")
{
isGrounded = true;
}
}
void OnCollisionExit2D(Collision2D, col)
{
if(col.gameObject.tag == "Ground")
{
isGrounded = false;
}
}
}
成为。
const promise = new Promise(() => {});
promise.catch(() => {});
promise.then(() => {});