Помогите пожалуйста. Как реализовать спавн АИ? Есть у меня код.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spawn : MonoBehaviour
{
// public GameObject obj2;
public GameObject obj;
bool logic;
// Start is called before the first frame update
void Start()
{
}
IEnumerator Instobj ()
{
yield return new WaitForSeconds(4.5f);
Instantiate(obj, obj.transform.position, Quaternion.identity);
// Instantiate(obj2, obj2.transform.position, Quaternion.identity);
// yield return new WaitForSeconds(4.5f);
}
// Update is called once per frame
void Update()
{
//if (GameObject.Find("Planedelete").GetComponent<TriggerDelete>().newDestroy == true)
if(Input.GetKey (KeyCode.F))
{
StartCoroutine(Instobj());
}
}
}
Данный код не работает. Если нажимать на F, то спавнит по 2, потом 3, потом 4 и т.д. Увеличивается в прогресии.