[英]Unity project Parser error
I am am having trouble with a piece of code from a tutorial i found online. 我在网上找到的教程中的一段代码遇到了麻烦。 i keep getting a parser error by the line
public static Vector2
. 我一直通过
public static Vector2
这一行收到解析器错误。
Here is the the code below. 这是下面的代码。 I can't find anything wrong with it and would love suggestions on why this error keeps coming up.
我找不到任何错误,并希望提出有关为什么此错误不断出现的建议。 Thanks!
谢谢!
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;
}
}
}
Error Message: 错误信息:
Parser Error: Unexpected symbol 'Vector2', expection 'class', 'delegate', 'enum', 'interface', partial', or 'struct'
解析器错误:意外的符号'Vector2',期望值'class','delegate','enum','interface',partial'或'struct'
Looks like you are closing the class after line: 看起来您正在下一行关闭课程:
public static Transform[,] grid = new Transform[w, h];
}
Move the brace to the end of the file. 将花括号移到文件末尾。
Also, any reason why everything is defined as static
? 此外,为什么将所有内容都定义为
static
? A MonoBehavior
is intended to be an instance object attached to a game object. MonoBehavior
旨在作为附加到游戏对象的实例对象。
Try this: You are closing the class to early and 尝试以下操作:您将尽早关闭课程,
public static bool isRowFull(int y) {
for (int x = 0; x < w; ++x)
if (grid[x, y] == null)
return false;
return true;
}
is missing brackets on the for loop. 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;
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.