replace gameobject after destroy,Replace Gameobject after destroying
Hi there,
My game is a car that runs into snowflakes (similar idea to fuel canisters) so i go through one it resets the cold value to 1 then destroys the gameobject. However i would like to respawn the snowflake again after a time delay incase the car crashes and has to respawn.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AddColdL2 : MonoBehaviour
{
public VanController vanController;
private void OnTriggerEnter2D(Collider2D collision)
{
vanController.cold = 1;
Destroy(gameObject);
}
}
How could i go about doing this?,
Answer by GameMaker1111 · Jun 01, 2020 at 09:39 PM
Hey, this is one way you can go about it for the delay you can use StartCoroutine and IEnumerator. Basically the StartCorotuine will call a function that is an IEnumerator function that allows you to use this yield return new WaitForSeconds(the time you want to take before snowflake returns) Here is an easy example I created of how coroutine works.
For the respawning maybe try and follow this link and see if that helps? link: https://answers.unity.com/questions/643081/help-me-with-simple-respawn-script-please-c.html I hope I was helpful.
Your answer
Follow this Question
Related Questions
Spawn and destroy gameObject by tag 0 Answers
Generated AssetBundle only works when created within same Unity Project? 0 Answers
Why aren't my prefab clones destroying on play mode exit? 1 Answer
Enemy Spawner Help 0 Answers
Destroying instantiated game objects from prefab when coliding with the ground 1 Answer