I’m Very new to unity and I’m making a game about tending to a campfire.
If it stays out longer than 15-30 seconds it’s game over. but if you relight the fire you stay alive.
rather than destroy the fire object and respawn it. I wish to teleport the fire object to a separate scene than teleport it back if it’s relit in time. does anyone know the code for this?
Here is my code for the campfire.
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine;
public class Extinguish : MonoBehaviour
{
public float timeLeft = 30;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
timeLeft -= Time.deltaTime;
if (timeLeft <= 0.0f)
{
Debug.Log("Fire Out");
}
if (timeLeft <= -15f)
{
Debug.Log("GameOver");
SceneManager.LoadScene("GameOver");
}
}
}
And here is my code for the campfire teleporting.
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine;
public class Gameovertimer : MonoBehaviour
{
public Extinguish public string m_Scene;
public GameObject m_CampFire;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (timeLeft <= -1f)
{
StartCoroutine(LoadYourAsyncScene());
}
}
IEnumerator LoadYourAsyncScene()
{
Scene currentScene = SceneManager.GetActiveScene();
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(m_Scene, LoadSceneMode.Additive);
{
while (!asyncLoad.isDone)
{
yield return null;
}
}
}
}