如何解决Unity中的错误CS0201以结束游戏



晚上好。我想问一下我遇到的Unity的问题。我制作了一个类似乒乓球的游戏,我制作了两个脚本,当球击中游戏后面的球时,将游戏场景转换为结果。然而,当我将它们插入墙和GameManagement对象时,出现了"错误CS0201:只有赋值、调用、递增、递减、等待和新对象表达式可以用作语句"的错误。我想知道这个问题的解决办法非常感谢。

游戏管理脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameMaster : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void GameOver()
{
SceneManager.LoadScene("Result");
}
}

墙检查是否命中的脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameoverPlayer1 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnCollisionEnter(Collision collision){
GameObject.Find("GameMaster").GetComponent<GameMaster>().GameOver;
}
}

您需要将GameOver作为方法调用。

GameObject.Find("GameMaster").GetComponent<GameMaster>().GameOver();

像这个

最新更新