My goal was to make an in-game asset (a platform), interactable so players can build towers on the platform.
When I add this script to a new section of platform, it works great! I click, select what I want to build, and the prefab is instantiated exactly where it should be on the platform. However, if I click on ANOTHER platform object with the same script and try to build again, the prefab is instantiated at the previous location. I don’t understand what’s going on–I thought each object with a script creates a new instance of itself, since I’m not using static references.
{
public Tower activeTower;
public Transform towerTransform;
public Tower towerToPlace;
public void BuildTowerOnPlatform(Tower towerToPlace)
{
activeTower = towerToPlace;
Tower placeTower =
Instantiate(activeTower,towerTransform.position,activeTower.transform.rotation);
UiController.instance.CloseTowerBuildPanel();
}
public void SelectTower() //use this on UI button
{
BuildTowerOnPlatform(towerToPlace);
}
}
Hope this piece of code is helpful–any ideas or approaches would be absolutely welcome! What on earth am I missing? I am at my wits end with this. A seemingly simple task has sent me down the rabbit hole.