I have a very plain script for a timer that explodes after it runs out. But the explosion effect is repeated 1000 times because it is inside Update. Where should i put Instantiate line so it’s not repeated every frame?
p.s. sorry if it sounds like a way too easy question - its not easy for me…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class timer : MonoBehaviour
{
TextMeshProUGUI mText;
public Transform SpecialEffectLocation;
public GameObject SpecialEffect;
public float theTimer = 10;
void Start()
{
mText = gameObject.GetComponent<TextMeshProUGUI>();
} void Update()
{
mText.text = theTimer.ToString("00");
if (theTimer > 0)
{
theTimer -= Time.deltaTime;
}
if (theTimer <= 0)
{
GameObject timer = Instantiate(SpecialEffect, SpecialEffectLocation.position, SpecialEffectLocation.rotation);
}
}
}