public void DestroyTile()
{
//TileX = new List<float>();
GameManager.Instance.SelectedTiles = new List<GameObject>();
GameManager.Instance.FirstTile = null;
GameManager.Instance.SecondeTile = null;
GameObject[] tObjects = GameObject.FindGameObjectsWithTag("Selected");
GameObject CTile;
GameManager.Instance.Arrows = 0;
for (int i = 0; i < tObjects.Length; i++)
{
CTile = tObjects[i];
Vector3Int currentCell = TileMap.WorldToCell(CTile.transform.position);
//currentCell.y++;
//Debug.Log(currentCell);
if(TileMap.GetTile<Tile>(currentCell) == Brown)
{
TileMap.SetTile(currentCell, null);
Game.GetComponent<FillTiles>().tilesnull.Add(currentCell);
}
Debug.Log("RY: " + Fade.transform.position.y);
RandomTile(CTile.transform.position.x, Fade.transform.position.y + i);
Destroy(CTile.GetComponent<Tiles>().currentArrow);
Destroy(CTile);
int tI = i + 1;
//Debug.Log("I: " + tI + " Object: " + tObjects.Length);
if (tI == tObjects.Length)
{
//Debug.Log("Y: " + currentCell.y + " X: "+ currentCell.x);
Game.GetComponent<FillTiles>().FloodFill(StartTile);
}
}
}
public void RandomTile(float RTileX, float RTileY)
{
Debug.Log("RTileY: " + RTileY);
GameObject newTile = Instantiate(tile, new Vector3(RTileX, RTileY, 0), tile.transform.rotation);
TileN++;
newTile.name = "Tile" + TileN;
newTile.GetComponent<Tiles>().ThisTile = newTile;
newTile.transform.parent = transform;
Sprite newSprite = characters[Random.Range(0, characters.Count)];
newTile.GetComponent<SpriteRenderer>().sprite = newSprite;
//Color color = new Color(255, 255, 255, 0);
//newTile.GetComponent<SpriteRenderer>().color = color;
newTile.GetComponent<SpriteRenderer>().enabled = false;
newTile.GetComponent<SpriteRenderer>().sortingOrder = 1;
}
}
I have this Script 3 times in my Level. 2 Times the Fade GameObject is the same and this works fine, but the last time its gives me back the Transform of the other Fade GameObject. I checkt a thousend times and in the inspector is the correct GameObject in the slot.