我在使用在线发现的教程中的一段代码时遇到了问题。我不断通过行public static Vector2
获得解析器错误。
以下是代码。我找不到它的任何问题,并且会喜欢为什么这个错误不断出现的建议。谢谢!
using UnityEngine;
using System.Collections;
public class Grid : MonoBehaviour {
// The Grid itself
public static int w = 10;
public static int h = 20;
public static Transform[,] grid = new Transform[w, h];
}
public static Vector2 roundVec2(Vector2 v) {
return new Vector2(Mathf.Round(v.x),
Mathf.Round(v.y));
}
public static void deleteRow(int y) {
for (int x = 0; x < w; ++x) {
Destroy(grid[x, y].gameObject);
grid[x, y] = null;
}
}
public static void decreaseRow(int y) {
for (int x = 0; x < w; ++x) {
if (grid[x, y] != null) {
// Move one towards bottom
grid[x, y-1] = grid[x, y];
grid[x, y] = null;
// Update Block position
grid[x, y-1].position += new Vector3(0, -1, 0);
}
}
}
public static void decreaseRow(int y) {
for (int x = 0; x < w; ++x) {
if (grid[x, y] != null) {
// Move one towards bottom
grid[x, y-1] = grid[x, y];
grid[x, y] = null;
// Update Block position
grid[x, y-1].position += new Vector3(0, -1, 0);
}
}
}
public static void decreaseRow(int y) {
for (int x = 0; x < w; ++x) {
if (grid[x, y] != null) {
// Move one towards bottom
grid[x, y-1] = grid[x, y];
grid[x, y] = null;
// Update Block position
grid[x, y-1].position += new Vector3(0, -1, 0);
}
}
}
public static bool isRowFull(int y) {
for (int x = 0; x < w; ++x)
if (grid[x, y] == null)
return false;
return true;
}
public static void deleteFullRows() {
for (int y = 0; y < h; ++y) {
if (isRowFull(y)) {
deleteRow(y);
decreaseRowsAbove(y+1);
--y;
}
}
}
错误讯息:
分析器错误:意外的符号'Vector2',预期'class','delegate','enum','interface',partial'或'struct'
答案 0 :(得分:2)
看起来你要在线后关闭课程:
public static Transform[,] grid = new Transform[w, h];
}
将大括号移动到文件的末尾。
此外,为什么所有内容都被定义为static
? MonoBehavior
旨在成为附加到游戏对象的实例对象。
答案 1 :(得分:0)
试试这个:你要提前关闭课程
public static bool isRowFull(int y) {
for (int x = 0; x < w; ++x)
if (grid[x, y] == null)
return false;
return true;
}
在for循环中缺少括号。
using UnityEngine;
using System.Collections;
public class Grid : MonoBehaviour {
// The Grid itself
public static int w = 10;
public static int h = 20;
public static Transform[,] grid = new Transform[w, h];
public static Vector2 roundVec2(Vector2 v) {
return new Vector2(Mathf.Round(v.x),
Mathf.Round(v.y));
}
public static void deleteRow(int y) {
for (int x = 0; x < w; ++x) {
Destroy(grid[x, y].gameObject);
grid[x, y] = null;
}
}
public static void decreaseRow(int y) {
for (int x = 0; x < w; ++x) {
if (grid[x, y] != null) {
// Move one towards bottom
grid[x, y-1] = grid[x, y];
grid[x, y] = null;
// Update Block position
grid[x, y-1].position += new Vector3(0, -1, 0);
}
}
}
public static void decreaseRow(int y) {
for (int x = 0; x < w; ++x) {
if (grid[x, y] != null) {
// Move one towards bottom
grid[x, y-1] = grid[x, y];
grid[x, y] = null;
// Update Block position
grid[x, y-1].position += new Vector3(0, -1, 0);
}
}
}
public static void decreaseRow(int y) {
for (int x = 0; x < w; ++x) {
if (grid[x, y] != null) {
// Move one towards bottom
grid[x, y-1] = grid[x, y];
grid[x, y] = null;
// Update Block position
grid[x, y-1].position += new Vector3(0, -1, 0);
}
}
}
public static bool isRowFull(int y) {
for (int x = 0; x < w; ++x) {
if (grid[x, y] == null)
return false;
}
return true;
}
public static void deleteFullRows() {
for (int y = 0; y < h; ++y) {
if (isRowFull(y)) {
deleteRow(y);
decreaseRowsAbove(y+1);
--y;
}
}
}
}