Upload Files
This commit is contained in:
parent
eda71bf923
commit
187c67f3d8
55
AI.cs
Normal file
55
AI.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using System.Collections;
|
||||
using static UnityEngine.GraphicsBuffer;
|
||||
|
||||
public class AI : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private NavMeshAgent agent;
|
||||
[SerializeField] private int waittime;
|
||||
[SerializeField] public Transform[] targets;
|
||||
private int currentTargetIndex;
|
||||
private bool isWaiting;
|
||||
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
targets = new Transform[3];
|
||||
|
||||
targets[0] = GameObject.Find("Cube (2)").transform;
|
||||
targets[1] = GameObject.Find("Cube (3)").transform;
|
||||
targets[2] = GameObject.Find("Cube (4)").transform;
|
||||
|
||||
if (targets.Length > 0)
|
||||
{
|
||||
currentTargetIndex = 0;
|
||||
SetNextDestination();
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!isWaiting && agent.remainingDistance <= agent.stoppingDistance && !agent.pathPending)
|
||||
{
|
||||
StartCoroutine(GoToNextTarget());
|
||||
}
|
||||
}
|
||||
|
||||
private void SetNextDestination()
|
||||
{
|
||||
if (targets.Length == 0)
|
||||
return;
|
||||
|
||||
agent.SetDestination(targets[currentTargetIndex].position);
|
||||
}
|
||||
|
||||
private IEnumerator GoToNextTarget()
|
||||
{
|
||||
isWaiting = true;
|
||||
yield return new WaitForSeconds(waittime);
|
||||
currentTargetIndex++;
|
||||
SetNextDestination();
|
||||
isWaiting = false;
|
||||
}
|
||||
}
|
17
Create.cs
Normal file
17
Create.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Create : MonoBehaviour
|
||||
{
|
||||
public GameObject[] objectToSpawn;
|
||||
public int z,y;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
int rand = UnityEngine.Random.Range(0, objectToSpawn.Length);
|
||||
Instantiate(objectToSpawn[rand], new Vector3(y,0,z), Quaternion.identity);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user