Hello Guys im pretty new at Unity and working now on my first 3D RPG game! I have one problem and im pretty sure someone can help me here.
Im working on my gather profession where I can gather plants and respawn them after a delay … all works pretty good but I have one problem. How I can store the positions to respawn them ? I have it know when I gather something and I respawn it it works and spawn on the exact position. When I have 2x plants and I wait until one is respawned it works too. But if I gather one and then I gather again one I have the problem that only 1 “plant” is respawned because he resets the bool and the position … Maybe someone can help me … Here is my code …
[SerializeField] private GameObject plant;
private Vector3 spawnPosition;
private bool isDestroyed = false;
private float respawnTimer = 0f;
private float waitTime = 10f;
private void Update()
{
if (isDestroyed)
{
respawnTimer += Time.deltaTime;
if (respawnTimer > waitTime)
{
Respawn();
respawnTimer = 0f;
}
}
}
public void Despawn(GameObject go)
{
spawnPosition = GetComponentInChildren<GatherLootTable>().MyStartPosition;
isDestroyed = true;
Destroy(go);
}
private void Respawn()
{
GameObject go = Instantiate(plant, spawnPosition, Quaternion.identity);
go.transform.parent = GameObject.FindWithTag("Botaniker").transform;
isDestroyed = false;
}