So I’m creating a game where you have to tend a campfire to prevent the enemies from moving closer and attacking you resulting in a game over. What I need to know is what kind of code would work to have the enemy teleport closer to you based on the time decreasing. I already have a timer script attached to the fire but then reset it’s position if the timer gets increased.
Here is the script for the fire
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine;
public class Gameovertimer : 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");
}
}
public void ButtonPressed()
{
if (timeLeft <= 0.0f)
timeLeft = 15;
}
}
Here is the script that increases the timer
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Wood : MonoBehaviour
{
public Extinguish extinguish;
void OnMouseDown()
{
Destroy(gameObject);
extinguish.timeLeft += 15;
}
}
I’m still learning about A.I so I don’t have a script for the enemy yet
I’m very new to unity so any help would be appreciated.