Hi, so I have this script that makes an item respawn after 5 seconds after being picked up. But once they respawn after 5 seconds, they no longer wait 5 seconds to respawn and instead respawn instantly. How do I make it so they always have to wait 5 seconds. Thanks!
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Respawn : MonoBehaviour {
private Vector3 spawnPos;
// Use this for initialization
void Start () {
spawnPos = transform.position;
}
// Update is called once per frame
void Update () {
Invoke("Spawn", 5f);
}
public void Spawn()
{
if (this.gameObject.tag == ("Respawn"))
{
transform.position = spawnPos;
}
}
}