我正在为我正在制作的游戏的主菜单上工作,我正在尝试制作新的/加载游戏系统,因为该游戏是2D的,我认为它应该只是将您当前的等级保存在playerpref中,并且是一个按顺序排列变量的数组,但是我只有一个测试级别,找不到找不到的括号,并且它也给了我一个CS1022“类型或名称空间定义或预期的文件结尾”,我认为缺少括号是原因,请帮助,我对CSharp来说还很陌生。
我的脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class MainMenuHandler : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
if (not(PlayerPrefs.HasKey("currentlevel"))) {
PlayerPrefs.SetFloat("currentlevel", 1);
}
public string[] levels = new string[1];
public string[] levels = new string[]{"Test"};
}
// Update is called once per frame
void Update()
{
}
//public void NewGame {
//
//}
}
答案 0 :(得分:2)
这是您代码的外观:
using UnityEngine;
public class MainMenuHandler : MonoBehaviour
{
public string[] levels = new string[1];
public string[] levelsTest = new string[] { "Test" };
// Start is called before the first frame update
void Start()
{
if (!(PlayerPrefs.HasKey("currentlevel")))
{
PlayerPrefs.SetFloat("currentlevel", 1);
}
}
// Update is called once per frame
void Update()
{
}
}