Looking to get a basic resource gathering system working and having some trouble respawning my resource. Right now I am just working with 2 objects, a Tree (the resource) and the Roots (where all the respawn code is)
Everything works fine until my Roots try to spawn a new Tree. It keeps giving me the error: object od type GameObject has been destroyed but you are still trying to access it. You should either check to see if its null or not destroy it.
Here is my code:
public float respawnTime;
public bool respawnCooldown = false;
public GameObject basicTree;
void Update ()
{
if (respawnCooldown == true)
{
if (respawnTime > 0)
{
respawnTime -= Time.deltaTime;
}
else
{
Respawn ();
}
}
public void Respawn ()
{
var tree = (GameObject)Instantiate(basicTree, transform.position, Quaternion.identity);
NetworkServer.Spawn (tree);
respawnCooldown = false;
respawnTime = 5;
}
}
I’m writing this to be a multiplayer game, hence the extra Spawn line below the instantiate. Both the Tree and the Roots are prefabs, with the Tree being a child of Roots.
Any help at all would be great!