using System.Collections; using System.Collections.Generic; using UnityEngine; public class tetromino : MonoBehaviour { public int timeBetweenSteps; public bool active = true; private float timer = 0.0f; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { timer += Time.deltaTime; if (timer >= timeBetweenSteps && active) { Debug.Log("Time elapsed!"); timer = timer - timeBetweenSteps; nextStep(); } } void nextStep() { if (validateFall()) { Fall(); } else { active = false; Fall(); } } private bool validateFall() { //Cast a ray to the next position of the tetromino. RaycastHit2D collision = Physics2D.Raycast(transform.position, Vector2.down, 1.0f); if (collision.collider != null) { //We hit something, but what? if (collision.collider.CompareTag("Ground") || collision.collider.CompareTag("Tetromino")) { Debug.Log("Collision with ground!"); return false; } Debug.Log("Collision!"); return false; } else { return true; } } void Fall() { transform.position += Vector3.down * 1.0f; } }