9d44c2f928
the ai person was able to fing the car like it has no mass add rigidbody with capsule collider to the ai person
43 lines
No EOL
1.1 KiB
C#
43 lines
No EOL
1.1 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
public class AiManager : MonoBehaviour
|
|
{
|
|
public Transform player;
|
|
public float cullingDistance;
|
|
public GameObject aiPrefab;
|
|
private GameObject[] _ais;
|
|
private float _distance;
|
|
public int maxAI;
|
|
private void Start()
|
|
{
|
|
StartCoroutine(Manager());
|
|
}
|
|
|
|
private void OnDrawGizmos()
|
|
{
|
|
Gizmos.color = Color.yellow;
|
|
Gizmos.DrawWireSphere(player.position, cullingDistance);
|
|
}
|
|
|
|
// ReSharper disable Unity.PerformanceAnalysis
|
|
private IEnumerator Manager()
|
|
{
|
|
while (true)
|
|
{
|
|
_ais = GameObject.FindGameObjectsWithTag("AIs");
|
|
if (_ais.Length < maxAI )
|
|
{
|
|
var instance = Instantiate(aiPrefab, gameObject.transform);
|
|
}
|
|
|
|
foreach (var i in _ais)
|
|
{
|
|
_distance = Vector3.Distance(i.transform.position, player.position);
|
|
if (_distance > cullingDistance) Destroy(i.gameObject);
|
|
}
|
|
|
|
yield return new WaitForSeconds(1);
|
|
}
|
|
}
|
|
} |