Right here is the code used for moving the pieces around. But I want to try a different approach for my game. Here's what I have: Code (CSharp): public class Piece : MonoBehaviour { float fall = 0; public float fallSpeed = 1; //Use this for initialization void Start() { } // Update is called once per frame void Update() { CheckUserInput(); } void CheckUserInput() { if (Input.GetKeyDown(KeyCode.RightArrow)) { transform.position += new Vector3(1, 0, 0); if (CheckIsValidPosition()) { FindObjectOfType<Board>().UpdateGrid(this); } else { transform.position += new Vector3(-1, 0, 0); } } else if (Input.GetKeyDown(KeyCode.LeftArrow)) { transform.position += new Vector3(-1, 0, 0); if (CheckIsValidPosition()) { FindObjectOfType<Board>().UpdateGrid(this); } else { transform.position += new Vector3(1, 0, 0); } } else if (Input.GetKeyDown(KeyCode.DownArrow) || Time.time - fall >= fallSpeed) { transform.position += new Vector3(0, -1, 0); if (CheckIsValidPosition()) { FindObjectOfType<Board>().UpdateGrid(this); } else { transform.position += new Vector3(0, 1, 0); enabled = false; FindObjectOfType<Board>().SpawnNextPiece(); } fall = Time.time; } } bool CheckIsValidPosition() { foreach (Transform unit in transform) { Vector2 pos = FindObjectOfType<Board>().Round (unit.position); if (FindObjectOfType<Board>().CheckIsInsideGrid (pos) == false) { return false; } if (FindObjectOfType<Board>().GetTransformAtGridPosition(pos) != null && FindObjectOfType<Board>().GetTransformAtGridPosition(pos).parent != transform) { return false; } } return true; } } I want to make it so that the pieces drop instantly to the bottom rather than slowly moving down. Any ideas?
When you decide to go down one line (line 42), instead of doing it, just set a variable, maybe like so: Code (csharp): int LinesToGoDown = 0; // left/right parts else if (Input.GetKeyDown(KeyCode.DownArrow) || Time.time - fall >= fallSpeed) { LinesToGoDown = 1; } else if (?WhateverIsAllTheWayDownKey?) { LinesToGoDown = 1000; // something big } Now finally do a for loop for the LinesToGoDown count, and do the "move down one line" code that was formerly in the "else if" block. ALSO, make that block terminate early if the block contacts the ones below it. Effectively the 1-down code will run as before, but the 1000-down code will (all in one frame) move the block down line by line, checking for it to hit.
I want to use only the down button for the insta-drop for the pieces to replace the other mechanic. And about this loop, how should I build this without errors popping up in my face? I have a bad habit of that happening.