Hey guys. I’m trying to make a game where Scrabble tiles fall down like Tetris tiles and when you make a word, it disappears like Tetris. I managed to make it with single letters but i cant figure out how to connect the letters together.
void RegisterTile()
{
gameLogic.grid[Mathf.FloorToInt(gameObject.transform.position.x), Mathf.FloorToInt(gameObject.transform.position.y)] = gameObject.transform;
TryWord();
}
bool CheckValid()
{
if(gameObject.transform.position.x > GameLogic.width ||
gameObject.transform.position.x < 0 ||
gameObject.transform.position.y < 0)
{
return false;
}
if (gameObject.transform.position.y < GameLogic.heigth && gameLogic.grid[Mathf.FloorToInt(gameObject.transform.position.x), Mathf.FloorToInt(gameObject.transform.position.y)] != null)
{
return false;
}
return true;
}
// Update is called once per frame
void Update()
{
if(CheckValid())
{
check = true;
}
if (!fingerDown && Input.GetMouseButtonDown(0))
{
startPos = Input.mousePosition;
fingerDown = true;
}
if (movable)
{
timer += 1 * Time.deltaTime;
if (Input.GetKey(KeyCode.DownArrow) && timer > GameLogicNew.quickDropTime || fingerDown && timer > GameLogic.quickDropTime && Input.mousePosition.y < startPos.y - pixelDistToDetect)
{
gameObject.transform.position -= new Vector3(0, 2, 0);
timer = 0;
if (!CheckValid())
{
movable = false;
gameObject.transform.position += new Vector3(0, 2, 0);
RegisterTile();
gameLogic.SpawnTile();
}
}
else if (timer > GameLogicNew.dropTime)
{
gameObject.transform.position -= new Vector3(0, 2, 0);
timer = 0;
if (!CheckValid())
{
movable = false;
gameObject.transform.position += new Vector3(0, 2, 0);
RegisterTile();
gameLogic.SpawnTile();
}
}
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
gameObject.transform.position -= new Vector3(2, 0, 0);
if (!CheckValid())
{
gameObject.transform.position += new Vector3(2, 0, 0);
}
}
else if (Input.GetKeyDown(KeyCode.RightArrow))
{
gameObject.transform.position += new Vector3(2, 0, 0);
if (!CheckValid())
{
gameObject.transform.position -= new Vector3(2, 0, 0);
}
}
if (fingerDown)
{
if (Input.mousePosition.x >= startPos.x + pixelDistToDetect)
{
gameObject.transform.position += new Vector3(2, 0, 0);
startPos = Input.mousePosition;
if (!CheckValid())
{
gameObject.transform.position -= new Vector3(2, 0, 0);
}
}
if (Input.mousePosition.x <= startPos.x - pixelDistToDetect)
{
gameObject.transform.position -= new Vector3(2, 0, 0);
startPos = Input.mousePosition;
if (!CheckValid())
{
gameObject.transform.position += new Vector3(2, 0, 0);
}
}
}
}
if (fingerDown && Input.GetMouseButtonUp(0))
{
fingerDown = false;
}
}
public void TryWord()
{
WordManager.currentWord += letterName.GetComponent<TMP_Text>().text;
Debug.Log(letterName.GetComponent<TMP_Text>().text);
}
it looks like this right now. When a letter hits the bottom, i can see it in the console but when multiple ones hit, i see them all together no matter where they are. I cant find a way to seperate them or show them in order (From left to right / from up to down). I couldnt find any tutorials on how to make a Scrabble game so i ask for your help. Thank you in advance.