Question by
LearningWhileScrewing · May 17, 2017 at 08:30 PM ·
scripting problem
Is this script old o.0?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class TetrisObject : MonoBehaviour {
float lastFall = 0f;
void Start () {
}
void Update () {
if (Input.GetKeyDown (KeyCode.LeftArrow)) {
transform.position += new Vector3 (-1, 0, 0);
if (IsValidGridPosition ()) {
UpdateMatrixGrid ();
} else {
transform.position += new Vector3 (1, 0, 0);
}
} else if (Input.GetKeyDown (KeyCode.RightArrow)) {
transform.position += new Vector3 (1, 0, 0);
if (IsValidGridPosition ()) {
UpdateMatrixGrid ();
} else {
transform.position += new Vector3 (-1, 0, 0);
}
} else if (Input.GetKeyDown (KeyCode.UpArrow)) {
transform.Rotate += new Vector3 (0, 0, -90);
if (IsValidGridPosition ()) {
UpdateMatrixGrid ();
} else {
transform.Rotate += new Vector3 (0, 0, 90);
}
} else if (Input.GetKeyDown (KeyCode.DownArrow) || Time.time - lastFall >= 1) {
transform.position += new Vector3 (0, -1, 0);
if (IsValidGridPosition ()) {
UpdateMatrixGrid ();
} else {
transform.position += new Vector3 (0, 1, 0);
MatrixGrid.DeleteWholeRows ();
FindObjectOfType<Spawner> ().SpawnRandom;
enabled = false;
}
lastFall = Time.time;
}
}
bool IsValidGridPosition() {
foreach (Transform child in Transform) {
Vector2 v = MatrixGrid.RoundVector (child.position);
if (!MatrixGrid.IsInsideBorder (v))
return false;
if(!MatrixGrid.grid[(int)v.x, (int)v.y] != null && MatrixGrid.grid[(int)v.x, (int)v,y].parent != transform)
} // this point is says TetrisObject.cs(67,3): error CS1525: Unexpected symbol `}'
return true;
}
void UpdateMatrixGrid() {
for (int y = 0; y < MatrixGrid.column; ++y) {
for (int x = 0; x < MatrixGrid.row; ++x) {
if(MatrixGrid.grid [x, y] != null) {
if (MatrixGrid.grid [x, y].parent == transform) {
MatrixGrid.grid [x, y] = null;
}
}
}
}
foreach (Transform child in transform) {
Vector2 v = MatrixGrid.RoundVector(child.position);
MatrixGrid.grid [(int)v.x, (int)x.y] = child;
}
}
} // TetrisObject
Comment
Likely syntax error. IsValidGridPosition should probably be:
bool IsValidGridPosition()
{
foreach (Transform child in Transform)
{
Vector2 v = $$anonymous$$atrixGrid.RoundVector (child.position);
if (!$$anonymous$$atrixGrid.IsInsideBorder (v))
return false;
if (!$$anonymous$$atrixGrid.grid[(int)v.x, (int)v.y] != null
&& $$anonymous$$atrixGrid.grid[(int)v.x, (int)v,y].parent != transform)
{
return true;
}
}
return true;
}
I fixed the syntax error your code had, as indicated by the line // this point is says TetrisObject.cs(67,3): error CS1525: Unexpected symbol '}'
If that is not the issue, then edit your question to make it clear what you are asking. Asking "Is This Script Old?" doesn't make any sense - the only thing related to Unity's API in this script is the Input calls, and those have not changed and would work just fine. Otherwise, this is all your own code or code that we would know nothing about - we can't tell you if your own code is old...