- Home /
Question by
mmuhammedckurtu · Sep 24, 2019 at 10:13 AM ·
c#instantiatespawnclonestetris
Tetris, Tetrominoes Clones Spawn Same Time
Hi, I am trying to make a tetris game and so I watch lots of tutorials and i take some codes from them. Now my tetris game can work at android device. But sometimes in android the spawner instantiate two tetraminoes(they are the shapes of tetris ex:L,I,O,S,Z) and bcause of this , game cannot be played. These are my Spawner codes(I have very poor coding).
I think Problem is nextTetromino and PreviewTetrominoes. How can i fixed this? Thanks.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spawner : MonoBehaviour {
public GameObject[] tetrominoes;
public GameObject previewTetramino;
public GameObject nextTetramino;
private Vector2 previewTetraminoPosition = new Vector2(15f, 9.0f);
private bool gameStarted = false;
// Use this for initialization
void Start () {
newTetramino();
}
public void newTetramino()
{
if (!gameStarted)
{
gameStarted = true;
nextTetramino = (GameObject)Instantiate(tetrominoes[Random.Range(0, tetrominoes.Length)], transform.position, Quaternion.identity);
previewTetramino = (GameObject)Instantiate(tetrominoes[Random.Range(0, tetrominoes.Length)], previewTetraminoPosition, Quaternion.identity) ;
previewTetramino.GetComponent<Ana>().enabled = false;
}
else
{
previewTetramino.transform.localPosition = new Vector2(4f, 16f);
nextTetramino = previewTetramino;
nextTetramino.GetComponent<Ana>().enabled = true;
previewTetramino = (GameObject)Instantiate(tetrominoes[Random.Range(0, tetrominoes.Length)], previewTetraminoPosition, Quaternion.identity);
previewTetramino.GetComponent<Ana>().enabled = false;
}
}
}
Comment