2015-10-28 18 views
-3

我一直在關注Unity3D 程序洞穴生成,但我在MapGeneration.cs很早就發現了一個錯誤。 Unity表示在第1行第1個字符處有一個錯誤:標識符預期:'public'是關鍵字。我看不出我的代碼和教程的代碼有什麼不同。這裏是鏈接到視頻教程:\Tutorial video 1]這裏是我的代碼:統一:第5行的錯誤CS1041:預期標識符:'public'是關鍵字?

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); 
       } 
      } 
     } 
    } 
} 

的錯誤是在一行公共

+0

在問題中你說第一行,但是它在第5行(就像你在標題中所說的那樣)。 –

回答

5

您在using System之後沒有;(也許這也是不完整的導入)。

+1

非常感謝!它立即修復它! –