- Home /
Tilemap wont update at random certain things;
I have recently been working on a random 2d golf course game inspired by the sx pectrum golf game and now i hvae come across a problem where many of my playtesters get to a point on the course and they then find they cant move in a certain direction anymore. This problem seems to hvae no pattern and i cant find a fix. I am using tilemaps to build the course then a second tilemap that changes the location of the ball based on user input in a text box. My code is below:
void powerSet() { inputField.ActivateInputField(); if (done2 != true) { if(backTilemap.GetTile(ball) == greenTile) { inputField.placeholder.GetComponent ().text = "Input power 1-3 (putting)"; lastBall = ball; } else { inputField.placeholder.GetComponent ().text = "Input power 1-8"; lastBall = ball; }
}
if (done2 == true)
{
directSet();
return;
}
if (Input.GetKeyDown("return"))
{
powerS = inputField.text;
inputField.text = "";
}
if (powerS == "1")
{
power = 1;
powerS = "";
}
if (powerS == "2")
{
power = 2;
powerS = "";
}
if (powerS == "3")
{
power = 3;
powerS = "";
}
if (powerS == "4" && backTilemap.GetTile(ball) != greenTile)
{
power = 4;
powerS = "";
}
if (powerS == "5" && backTilemap.GetTile(ball) != greenTile)
{
power = 5;
powerS = "";
}
if (powerS == "6" && backTilemap.GetTile(ball) != greenTile)
{
power = 6;
powerS = "";
}
if (powerS == "7" && backTilemap.GetTile(ball) != greenTile)
{
power = 7;
powerS = "";
}
if (powerS == "8" && backTilemap.GetTile(ball) != greenTile)
{
power = 8;
powerS = "";
}
if (power != 0)
{
done2 = true;
}
}
void directSet()
{
if (done3 != true)
{
inputField.placeholder.GetComponent<Text>().text = "Input compass direction";
lastBall = ball;
}
if (done3 == true)
{
StartCoroutine (Move());
return;
}
if (Input.GetKeyDown("return"))
{
direct = inputField.text;
if (backTilemap.GetTile(ball) == treeTile && UnityEngine.Random.Range(1,11) <= 6)
{
statusText.text = "You rebound off a tree";
power = 0;
reboundTree = true;
}
if (backTilemap.GetTile(ball) == sandTile)
{
power = power - UnityEngine.Random.Range(2, 5);
if (power < 1)
{
power = 1;
}
}
if (backTilemap.GetTile(ball) == roughTile)
{
power = power - UnityEngine.Random.Range(1, 4);
if (power < 1)
{
power = 1;
}
}
inputField.text = "";
}
if (UnityEngine.Random.Range(1, 8) == 7)
{
sidePower = UnityEngine.Random.Range(-1, 2);
}
if (direct == "E" || direct == "e")
{
ball.x = ball.x + power;
ball.y = ball.y + sidePower;
tilemap.ClearAllTiles();
tilemap.SetTile(ball, tile);
direct = "";
done3 = true;
}
if (direct == "W" || direct == "w")
{
ball.x = ball.x - power;
ball.y = ball.y + sidePower;
tilemap.ClearAllTiles();
tilemap.SetTile(ball, tile);
direct = "";
done3 = true;
}
if (direct == "N" || direct == "n")
{
ball.y = ball.y + power;
ball.x = ball.x + sidePower;
tilemap.ClearAllTiles();
tilemap.SetTile(ball, tile);
direct = "";
done3 = true;
}
if (direct == "S" || direct == "s")
{
ball.y = ball.y - power;
ball.x = ball.x + sidePower;
tilemap.ClearAllTiles();
tilemap.SetTile(ball, tile);
direct = "";
done3 = true;
}
if (direct == "SE" || direct == "se")
{
ball.y = ball.y - power;
ball.x = ball.x + power;
tilemap.ClearAllTiles();
tilemap.SetTile(ball, tile);
direct = "";
done3 = true;
}
if (direct == "SW" || direct == "sw")
{
ball.y = ball.y - power;
ball.x = ball.x - power;
tilemap.ClearAllTiles();
tilemap.SetTile(ball, tile);
direct = "";
done3 = true;
}
if (direct == "NE" || direct == "ne")
{
ball.y = ball.y + power;
ball.x = ball.x + power;
tilemap.ClearAllTiles();
tilemap.SetTile(ball, tile);
direct = "";
done3 = true;
}
if (direct == "NW" || direct == "nw")
{
ball.y = ball.y + power;
ball.x = ball.x - power;
tilemap.ClearAllTiles();
tilemap.SetTile(ball, tile);
direct = "";
done3 = true;
}
}
IEnumerator Move()
{
score += 1;
done2 = false;
done3 = false;
power = 0;
if (reboundTree == true)
{
yield return new WaitForSeconds(3);
}
if (backTilemap.GetTile(ball) == holeTile)
{
backing1.SetActive(true);
statusText.text = "You holed out in " + score;
yield return new WaitForSeconds(0.5f);
ballSheet = GetComponent<TilemapRenderer>();
ballSheet.enabled = false;
yield return new WaitForSeconds(2);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
if (backTilemap.GetTile(ball) == waterTile)
{
statusText.text = "In the water";
tilemap.ClearAllTiles();
tilemap.SetTile(lastBall, tile);
}
if (ball.y >= 12 || ball.x <= -17 || ball.y <= -10 || ball.x >= 16)
{
statusText.text = "Out of bounds";
tilemap.ClearAllTiles();
tilemap.SetTile(lastBall, tile);
ball = lastBall;
}
if (backTilemap.GetTile(ball) == sandTile)
{
statusText.text = "In the bunker";
}
if (backTilemap.GetTile(ball) == roughTile)
{
statusText.text = "In the rough";
}
if (backTilemap.GetTile(ball) == treeTile)
{
statusText.text = "In the trees";
}
if (backTilemap.GetTile(ball) == fairTile)
{
statusText.text = "On the fairway";
}
if (backTilemap.GetTile(ball) == teeTile)
{
statusText.text = "On the tee";
}
if (backTilemap.GetTile(ball) == greenTile)
{
statusText.text = "On the green (max power 3)";
}
backing.SetActive(false);
reboundTree = false;
Hope you can help
Your answer
Follow this Question
Related Questions
Problem with floor generator. 2 Answers
Line Renderer moves for no apperent reason 0 Answers
Does anyone know how to fix this tilemap render issue? 0 Answers
Weird blue lines in scene and game view. 0 Answers
Why are tilemaps so bad ? 2 Answers