public void DrawGhost(tetris_Shape originalShape, tetris_Board gameBoard) { if (!m_ghostShape) { m_ghostShape = Instantiate(originalShape, originalShape.transform.position, originalShape.transform.rotation) as tetris_Shape; m_ghostShape.gameObject.name = "GhostShape"; SpriteRenderer[] allRenders = m_ghostShape.GetComponentsInChildren <SpriteRenderer>(); foreach (SpriteRenderer r in allRenders) { r.color = m_color; } } else { m_ghostShape.transform.position = originalShape.transform.position; m_ghostShape.transform.rotation = originalShape.transform.rotation; m_ghostShape.transform.localScale = Vector3.one; } m_hitBottom = false; while (!m_hitBottom) { m_ghostShape.MoveDown(); if (!gameBoard.IsValidPosition(m_ghostShape)) { m_ghostShape.MoveUp(); m_hitBottom = true; } } }
// Use this for initialization void Start() { //if (diagnosticText){diagnosticText.text = "";} //m_gameBoard = GameObject.FindWithTag("Board").GetComponent<tetris_Board>(); // m_gameBoard = GameObject.FindObjectsOfType<tetris_Board>(); m_timeToNextKeyLeftRight = Time.time + m_keyRepeatRateLeftRight; m_timeToNextKeyDown = Time.time + m_keyRepeatRateDown; m_timeToNextKeyRotate = Time.time + m_keyRepeatRateRotate; m_gameBoard = GameObject.FindObjectOfType(typeof(tetris_Board)) as tetris_Board; m_spawner = GameObject.FindWithTag("Spawner").GetComponent <tetris_Spawner>(); m_soundManager = GameObject.FindObjectOfType <tetris_SoundManager>(); m_scoreManager = GameObject.FindObjectOfType <tetris_ScoreManager>(); m_ghost = GameObject.FindObjectOfType <tetris_Ghost>(); m_holder = GameObject.FindObjectOfType <tetris_Holder>(); if (!m_scoreManager) { Debug.LogWarning("WARNING! There is no scoreManager defined!"); } if (!m_soundManager) { Debug.LogWarning("WARNING! There is no soundManager defined!"); } if (!m_gameBoard) { Debug.Log("WARNING! There is no game board defined"); } if (!m_spawner) { Debug.Log("WARNING! There is no game spawner defined"); } else { m_spawner.transform.position = tetris_Vectorf.Round(m_spawner.transform.position); if (!m_activeShape) { m_activeShape = m_spawner.SpawnShape(); } } if (m_gameOverPanel) { m_gameOverPanel.SetActive(false); } if (m_gamePausePanel) { m_gamePausePanel.SetActive(false); } m_dropIntervalModded = m_dropInterval; }