Prefab not updating its position.
Prefab being instantiated on a flat grid where ever i choose with mouse click using TerrainGridSystem (see asset store), its a grid basically, the Vector3 position showing on instantiation is 0,0,0.
The prefab is being instantiated on the centre of the Tile/Box under the mouse position.
I have a button baked into the prefab, I want to use the button on the prefab to move a “ship” Object the the clone position.
Problem is It is returning the prefabs position (0,0,0) using Debug.Log to get this data.
I hope i was clear with my description all help is greatly appreciated.
namespace TGS {
public class TestSpawn : MonoBehaviour {
// “Ship” prefab
[SerializeField] GameObject prefab;
private int _maxMoveHereButtons = 2;
static int btncount = 0;
public static GameObject _prefabClone;
private Vector3 prefabClonePos;
[SerializeField] Rigidbody ship;
private Cell cell;
TerrainGridSystem tgs;
void Start ()
{
tgs = TerrainGridSystem.instance;
tgs.OnCellClick += Tgs_OnCellClick;
}
// Spawner, Where ever i click on the map (Map has a grid system in place)
// it instantiates the prefab on the center of the box under the mouse position.
private void Tgs_OnCellClick(TerrainGridSystem sender, int cellIndex, int buttonIndex) {
if (buttonIndex == 1) {
if (prefab != null)
{
if (btncount >= _maxMoveHereButtons) return;
_prefabClone = Instantiate(prefab);
_prefabClone.transform.position = tgs.CellGetPosition(cellIndex, true, 1f);
//_prefabClone.name = "Move To Here UI Button";
_prefabClone.tag = "First";
if (_prefabClone.CompareTag("First"))
{
prefabClonePos = transform.position;
}
btncount++;
}
}
}
// Button baked into prefab*
public void buttonclick()
{
if (_prefabClone.tag != "First") return;
Debug.Log("Move" + prefabClonePos);
ship.transform.DOMove(prefabClonePos, 50);
}
}