Destroying a prefab bullet after time with the list
Good night,
I am producing a project where I need to throw objects and after a while they self-destruct, but all very quickly, since I send teleport. I can normally destroy the first prefab that the player shoots, but the next one is intact, being deleted only from the list and not being destroyed, I have been trying to solve this problem for a long time and I am new to programming.
Obs¹: I can't use "Destroy (gameObject);" since he gives the following error and I need the player to teleport as soon as possible:
"The object of type 'GameObject' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object."
Obs²: Sorry for my bad English, I'm not very fluent.
My attempt:
IEnumerator onDestroy()
{
yield return new WaitForSeconds(timerRange);
rb2b.constraints = RigidbodyConstraints2D.FreezePosition;
yield return new WaitForSeconds(timerRange);
Destroy(playerController.projectiles[playerController.projectiles.Count - 1]);
playerController.projectiles.RemoveAt(playerController.projectiles.Count - 1);
}
Your answer
Follow this Question
Related Questions
How to create a portal/teleport. 2 Answers
Struggling with creating a Slender-like AI (Creating this for educational purposes) 0 Answers
how can i destroy the object when life get 0?,how can i destroy a object when life get 0? 0 Answers
Teleportation with gun 2 Answers
Google VR: Teleport the GVRMain Camera on a plane after looking on specified Cube to another Plane 0 Answers