From eda71bf923011915f1ef312817420b5450fb6225 Mon Sep 17 00:00:00 2001 From: eblo69 Date: Sun, 8 Sep 2024 15:42:33 +0000 Subject: [PATCH 1/4] Update README.md --- README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ef84e6a..406a8df 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ -# UnityBiz -Kozub likes giving exercises!!!! - -[![Watch the video](https://img.youtube.com/vi/T-D1KVIuvjA/maxresdefault.jpg)](https://streamable.com/6w5oqj) \ No newline at end of file +Bake NavMesh: +Wybierz teren, który ma być powierzchnią do nawigacji (np. Plane). +Przejdź do zakładki Window -> AI -> Navigation. +W sekcji Bake kliknij przycisk Bake, aby wygenerować NavMesh na obiekcie. +Dodaj komponent NavMeshAgent do obiektu AI: +Stwórz nowy obiekt 3D (np. Sphere lub Cube), który będzie agentem AI. +Do tego obiektu dodaj komponent NavMesh Agent (w zakładce Inspector -> Add Component -> wpisz NavMeshAgent). +Podłącz skrypt AI do agenta: +Do obiektu AI dodaj załączony skrypt AI (AI.cs). +W Inspector w polu Agent przypisz komponent NavMeshAgent, a w polu Wait Time ustaw odpowiednią liczbę sekund (np. 2). \ No newline at end of file From 187c67f3d8138dc5706ab5bfbc1ac0de9610935b Mon Sep 17 00:00:00 2001 From: eblo69 Date: Sun, 8 Sep 2024 15:56:04 +0000 Subject: [PATCH 2/4] Upload Files --- AI.cs | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Create.cs | 17 +++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 AI.cs create mode 100644 Create.cs diff --git a/AI.cs b/AI.cs new file mode 100644 index 0000000..4b50c0e --- /dev/null +++ b/AI.cs @@ -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; + } +} diff --git a/Create.cs b/Create.cs new file mode 100644 index 0000000..6463220 --- /dev/null +++ b/Create.cs @@ -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); + } +} From 468088ddfdf6acbc648857047632e79b28794905 Mon Sep 17 00:00:00 2001 From: Nukie Date: Tue, 17 Sep 2024 22:54:40 +0000 Subject: [PATCH 3/4] Update cos do ai.md --- README.md => cos do ai.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README.md => cos do ai.md (100%) diff --git a/README.md b/cos do ai.md similarity index 100% rename from README.md rename to cos do ai.md From a4e983a4a9ff8d5454c4b8001031ff65894172e9 Mon Sep 17 00:00:00 2001 From: Nukie Date: Tue, 17 Sep 2024 22:55:42 +0000 Subject: [PATCH 4/4] Add README --- README | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..ef84e6a --- /dev/null +++ b/README @@ -0,0 +1,4 @@ +# UnityBiz +Kozub likes giving exercises!!!! + +[![Watch the video](https://img.youtube.com/vi/T-D1KVIuvjA/maxresdefault.jpg)](https://streamable.com/6w5oqj) \ No newline at end of file