Hello,
I am having a bit of trouble instantiating a prefab on a tile cell position.
I am working on a farming game and i want to instantiate a plant prefab on the field tile the Player is standing on.
I tried to parent the grid while instantiating but that just spawns the plant right under the player.
I want it to snap to the middle of the cell.
Here is my code :
void Update()
{
if(Input.GetButtonDown("Interact") && tilemap.GetTile(tilemap.WorldToCell(transform.position)).name.Contains("GrassTile"))
{
tilemap.SetTile(tilemap.WorldToCell(gameObject.transform.position), FieldTile);
}
else if(Input.GetButtonDown("Interact") && tilemap.GetTile(tilemap.WorldToCell(transform.position)).name.Contains("FieldTile"))
{
Instantiate(Plant, transform.position, Quaternion.identity, grid);
}
}
Im sure there must be a simple solution to this that im not finding.