i am getting this error , what might be wrong in my script;This is a GameManget.cs script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour
{
public static GameManager singleton;
public bool GameStarted { get; private set; }
public bool GameEnded { get; private set;}
// Start is called before the first frame update
private void Awake()
{
if (singleton == null)
{
singleton = this;
}
else if(singleton != this)
{
Destroy(gameobject);
}
}
public void StartGame()
{
GameStarted = true;
Debug.Log("Game Started");
}
public void EndGame(bool win)
{
GameEnded = true;
Debug.Log("Game Ended");
if (!win)
{
//Restart the game
Invoke("RestartGame",2);
}
}
public void RestartGame()
{
UnityEngine.SceneManagement.SceneManager.LoadScene(0);
}
}
And this is the scrpt for my ball controller
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ballcontroller : MonoBehaviour
{
[SerializeField] private float thrust = 150f;
[SerializeField] private Rigidbody rb;
[SerializeField] private float wallDistance = 5f;
[SerializeField] private float minCamDistance = 3f;
private Vector2 lastMousePos;
// Update is called once per frame
void Update()
{
Vector2 deltaPos = Vector2.zero;
if(Input.GetMouseButton(0))
{
Vector2 currentMousePos = Input.mousePosition;
if(lastMousePos == Vector2.zero)
lastMousePos = currentMousePos;
deltaPos = currentMousePos - lastMousePos;
lastMousePos = currentMousePos;
Vector3 force = new Vector3(deltaPos.x, 0, deltaPos.y) * thrust;
rb.AddForce(force);
}
else
{
lastMousePos = Vector2.zero;
}
}
private void FixedUpdate()
{
if (GameManager.singleton.GameEnded)
return;
if (GameManager.singleton.GameStarted)
{
rb.MovePosition(transform.position + Vector3.forward * 5 * Time.fixedDeltaTime);
}
}
private void LateUpdate()
{
Vector3 pos = transform.position;
if(transform.position.x < -wallDistance)
{
pos.x = -wallDistance;
}
else if(transform.position.x > wallDistance)
{
pos.x = wallDistance;
}
if(transform.position.z < Camera.main.transform.position.z + minCamDistance)
{
pos.z = Camera.main.transform.position.z + minCamDistance;
}
transform.position = pos;
}
private void OnCollisionEnter(Collision collision)
{
if(GameManager.singleton.GameEnded)
return;
if(collision.gameObject.tag == "Death")
GameManager.singleton.EndGame(false);
}
}