Поэтому после того, как я внес изменения в свой код, ошибок больше не было. Но когда я играл в игру, игрок просто двигался прямо вверх, и я терял всякий контроль. Может ли кто-нибудь помочь мне исправить мой код, чтобы этого не произошло?
Это мой код:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement1 : MonoBehaviour
{
private float speed;
public Rigidbody2D rigidbody;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
Vector2 direction = new Vector2(horizontalInput, verticalInput);
rigidbody.velocity = direction * speed;
rigidbody.gravityScale = 0;
}
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... -player-wi