Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Random = UnityEngine.Random;
- public class AIManager : MonoBehaviour, IAIManager {
- [SerializeField] private GameObject[] civilianPrefabs;
- private AstarPath astar;
- private int activeActors;
- private List<Vector3> destinationPoints = new List<Vector3>();
- private void Awake() {
- astar = GetComponent<AstarPath>();
- }
- public void SpawnActor() {
- Vector3 randomSpawn = destinationPoints[Random.Range(0, destinationPoints.Count)];
- GameObject newActor = Instantiate(civilianPrefabs[Random.Range(0,civilianPrefabs.Length)], randomSpawn, Quaternion.identity, transform);
- Civilian newCivilian = newActor.GetComponent<Civilian>();
- newCivilian.SetAstar(this);
- newCivilian.SetDestination(destinationPoints[Random.Range(0, destinationPoints.Count)]);
- }
- public Vector3 GetNewDestination() {
- return destinationPoints[Random.Range(0, destinationPoints.Count)];
- }
- public void AddSpawnPoint(Vector3 newSpawnPoint) {
- destinationPoints.Add(newSpawnPoint);
- }
- public void RemoveDestinationPoint(Vector3 newDestinationPoint) {
- if(destinationPoints.Contains(newDestinationPoint)) {
- destinationPoints.Remove(newDestinationPoint);
- }
- }
- public void UpdateNavMesh(Vector3 position) {
- astar.UpdateGraphs(new Bounds(position, new Vector3(5,5,5)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement