error CS0120: An object reference is required to access non-static member `Groups.numberOfRowsThisTurn'
I am adding scoring to my Tetris game and received this error, Assets/Groups.cs(79,17): error CS0120: An object reference is required to access non-static member `Groups.numberOfRowsThisTurn'. I have tried to look it up online but I still can't figure out what the problem is. Please help.
Here is my code:
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class Groups : MonoBehaviour {
public static int gridWidth = 10;
public static int gridHeight = 20;
public static Transform[,] grid = new Transform[gridWidth, gridHeight];
public int scoreOneLine = 40;
public int scoreTwoLine = 100;
public int scoreThreeLine = 300;
public int scoreFourLine = 1200;
public Text hub_score;
private int numberOfRowsThisTurn = 0;
private int CurrentScore;
void update() {
updateScore ();
updateUI ();
}
public void updateUI() {
hub_score.text = CurrentScore.ToString ();
}
public void updateScore(){
if (numberOfRowsThisTurn > 0) {
if (numberOfRowsThisTurn == 1) {
clearedOneLine ();
} else if (numberOfRowsThisTurn == 2) {
clearedTwoLines ();
} else if (numberOfRowsThisTurn == 3) {
clearedThreeLines ();
} else if (numberOfRowsThisTurn == 4) {
clearedFourLines ();
}
numberOfRowsThisTurn = 0;
}
}
void clearedOneLine(){
CurrentScore += scoreOneLine;
}
void clearedTwoLines(){
CurrentScore += scoreTwoLine;
}
void clearedThreeLines(){
CurrentScore += scoreThreeLine;
}
void clearedFourLines(){
CurrentScore = +scoreFourLine;
}
public static Vector2 round(Vector2 v) {
return new Vector2(Mathf.Round(v.x), Mathf.Round(v.y));
}
public static bool isInsideGrid(Vector2 pos) {
return ((int)pos.x >= 0 &&
(int)pos.x < gridWidth &&
(int)pos.y >= 0);
}
public static void Delete(int y) {
for (int x = 0; x < gridWidth; ++x) {
Destroy(grid[x, y].gameObject);
grid[x, y] = null;
}
}
public static bool isFull(int y) {
for (int x = 0; x < gridWidth; ++x) {
if (grid [x, y] == null) {
return false;
}
}
numberOfRowsThisTurn ++; //<---- error here
return true;
}
First you are missing a brace at the end of the file (you probably missed it on copying it). But you need to let us know exactly where the error is occurring because a line number does not help when what you pasted into UA is all messed up. Do something like this
//<---- error here
on the line where the error is.
Thank you. I will mark the line with the error.