Пожалуйста, извините меня, я полный новичок во всем этом, но я пытаюсь сделать игру после "Brackeys Как сделать видеоигру", я нахожусь на видео 8, если это поможет. Кажется, я не могу найти то, что сделал неправильно, я добавил свои сценарии для «движения игрока», «столкновения игрока» и «менеджера игры». Пожалуйста, если есть что-то еще, что вам нужно, чтобы помочь мне, пожалуйста, спросите, я действительно не хочу сдаваться, но мне действительно нравилось делать это Спасибо всем
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
// This is a reference to the Rigidbody component called "rb"
public Rigidbody rb;
public float forwardForce = 2000f; // Variable that determines the forward force
public float sidewaysForce = 500f; // Variable that determines the sideways force
// We marked this as "Fixed"Update because we
// are using it to mess with physics.
void FixedUpdate ()
{
// Add a forward force
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
if (Input.GetKey("d")) // If the player is pressing the "d" key
{
// Add a force to the right
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (Input.GetKey("a")) // If the player is pressing the "a" key
{
// Add a force to the left
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (rb.position.y < -1f)
{
FindObjectOfType<GameManager>().EndGame();
}
}
}
using UnityEngine;
public class PlayerCollision : MonoBehaviour {
public PlayerMovement movement; // A reference to our PlayerMovement script
// This function runs when we hit another object.
// We get information about the collision and call it "collisionInfo".
void OnCollisionEnter (Collision collisionInfo)
{
// We check if the object we collided with has a tag called "Obstacle".
if (collisionInfo.collider.tag == "Obstacle")
{
movement.enabled = false; // Disable the players movement.
FindObjectOfType<GameManager>().EndGame();
}
}
}
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour {
bool gameHasEnded = false;
public float restartDelay = 1f;
public GameObject completeLevelUI;
public void CompleteLevel ()
{
completeLevelUI.SetActive(true);
}
public void EndGame ()
{
if (gameHasEnded == false)
{
gameHasEnded = true;
Debug.Log("GAME OVER");
Invoke("Restart", restartDelay);
}
}
void Restart ()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
, когда я падаю с земли: NullReferenceException: Ссылка на объект не установлена на экземпляр объекта PlayerMovement.FixedUpdate () (в Assets / Scripts / PlayerMovement.cs : 32)
при столкновении с препятствием: NullReferenceException: ссылка на объект не установлена на экземпляр объекта PlayerCollision.OnCollisionEnter (UnityEngine.Collision collisionInfo) (в Assets / Scripts / PlayerCollision.cs: 15)