Unity:第5行出现错误CS1041:需要标识符:';公共';是一个关键字

本文关键字:公共 关键字 一个 标识符 5行 错误 CS1041 Unity | 更新日期: 2023-09-27 18:19:30

我一直在关注Unity3D程序洞穴生成,但我很早就在MapGeneration.cs中发现了一个错误。Unity说,在第1行单词1上,有一个错误:应为标识符:'public'是关键字。我看不出我的代码和教程的代码有什么不同。这是教程视频的链接:[''tutorial video1],这是我的代码:

using UnityEngine;
using System.Collections;
using System
public class MapGeneration : MonoBehaviour {
    public int width;
    public int height;
    public string seed;
    public bool useRandomSeed;
    [Range(0,100)]
    public int randomFillPercent;
    int[,] map;
    void Start() {
        GenerateMap();
    }
    void GenerateMap() {
        map = new int[width,height];
    }
    void RandomFillMap() {
        if (useRandomSeed) {
            seed = Time.time.ToString();
        }
        System.Random psuedoRandom = new System.Random(seed.GetHashCode());
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y ++) {
                map[x,y] = (psuedoRandom.Next(0,100) < randomFillPercent)? 1: 0;
            }
        }
    }
    void OnDrawGizmos() {
        if (map != null) {
            for (int x = 0; x < width; x++) {
                for (int y = 0; y < height; y ++) {
                    Gizmos.color = (map[x,y] == 1)? Color.black: Color.white;
                    Vector3 position = new Vector3(-width/2 + x + .5f,0,-height/2 + y + .5f);
                    Gizmos.DrawCube(position,Vector3.one);
                }
            }
        }
    }
}

错误是第一行的公共

Unity:第5行出现错误CS1041:需要标识符:';公共';是一个关键字

using System之后没有;(这可能也是一个不完整的导入)。