Hi, Im having a problem limiting how many times that invoke repeating is called, I want it to stop placing cars once it has placed 5 of them, how can I script that?
Here is my current script,
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InfiniteCar : MonoBehaviour
{
public GameObject car;
public int carLimit;
private int carCount;
void Start()
{
InvokeRepeating("Inst", 2f, 2f);
}
void Inst()
{
Instantiate (car, transform.position, transform.rotation);
}
private void Update()
{
if (carLimit < carCount)
CancelInvoke();
}
}