Hi everyone I have a little problem here, I have already checked here and on google but nothing seems to help to solve my problem so here we are, I have a list of spawn points
spawnPointList = new List<SpawnPoint>();
and I have 3 classes (pickup controller, spawn point and player controller).
Inside the class pickup controller I instantiate for every spawn point a pickup and i set the availability as false:
void Start()
{
//spawn the first pickups on every spawnPoint and after set them unavailable
foreach (SpawnPoint spawn in spawnPointList)
{
SpawnPickup(spawn.GetID());
spawn.available = false;
}
}
As you can see I have an ID for every spawn point (3 spawn point at the moment).
Inside the Player controller I check if I collided with a pick up and from the same function i set some needed data in the pickup controller:
void OnControllerColliderHit (ControllerColliderHit hit)
{
if (hit.gameObject.tag == "Pickup")
{
Pickup_controller.collision = true;
Pickup_controller.object_hit = hit.gameObject;
}
}
After that, in the pickup controller update, I call the function that destroy the pickup:
void Update()
{
SpawnPoint spawn = spawnPointList.Find (x => x);
//on collision with a pick up we destroy it and spawn another one on that spawn point after a while
if (Pickup_controller.collision == true)
{
//this is the function that delete the pick up
Collected(Pickup_controller.object_hit);
time -= (Time.deltaTime / Time.deltaTime);
if (spawn.available == true)
{
if(time < 0)
{
SpawnPickup(spawn.GetID());
spawn.Availability(false);
}
}
}
}
Well now the problem is: I can’t just disable the pickup to enable it back later, I really have to destroy it and place another NEW one in the empty spawn point but from here I don’t know how to retrieve the empty spawn point after i destroy the pick up.
Already tried to save the pickup in another Game object calling the delete function delete the copy too.
The problem isn’t the pickup (because in the future I have to take the pickup and put into inventory so have to left the scene) the problem is how to retrieve the exact empty spawn point in the list after i destroy “its” pick up.
I create a public ID component for every spawn point thinking it might come in handy.
Thank you in advance.
PS.: Right now (clearly) in the pickup controller update function after the delete of the pickup, and after a while, a new pickup is spawned on the empty spawn point but doesn’t work because after the start function in pickup controller the availability remain false.