From 60d9ce6eef3a3134532df3120b30b349da9c5e06 Mon Sep 17 00:00:00 2001 From: NickFowler Date: Sat, 1 Feb 2020 20:50:48 +1100 Subject: [PATCH] Kill zone and win and lose states --- Assets/Scenes/SampleScene.unity | 34 ++++++++++++++++++++++-- Assets/Scripts/Gameplay/KillZone.cs | 28 +++++++++++++++++++ Assets/Scripts/Gameplay/KillZone.cs.meta | 11 ++++++++ Assets/Scripts/Gameplay/Objective.cs | 22 +++++++++++++-- Assets/Scripts/Input/HerdController.cs | 1 + 5 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 Assets/Scripts/Gameplay/KillZone.cs create mode 100644 Assets/Scripts/Gameplay/KillZone.cs.meta diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 6540f4f..03eb7cc 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -430,6 +430,36 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 6 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &383701014 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 383701015} + m_Layer: 0 + m_Name: Spawn + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &383701015 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 383701014} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0.5, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 10 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &705507993 GameObject: m_ObjectHideFlags: 0 @@ -911,11 +941,11 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: Prefab: {fileID: 7371939184051845554, guid: f5c2c9744b6f46e4e95ca41ab1d8d560, type: 3} - HerdCount: 20 + HerdCount: 100 SpawnPoint: {fileID: 0} WaitTime: 0.2 Centre: {fileID: 338695193} - GameState: {fileID: 0} + GameState: {fileID: 1065404630} --- !u!4 &1457452761 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Gameplay/KillZone.cs b/Assets/Scripts/Gameplay/KillZone.cs new file mode 100644 index 0000000..0e9d2f4 --- /dev/null +++ b/Assets/Scripts/Gameplay/KillZone.cs @@ -0,0 +1,28 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class KillZone : MonoBehaviour +{ + public HerdController herd; + + // Start is called before the first frame update + void Start() + { + herd = FindObjectOfType(); + } + + private void OnTriggerEnter(Collider other) + { + Debug.Log("Hit"); + PlayerController horse = other.GetComponent(); + if (horse != null) + herd.RemoveHorse(horse); + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/Gameplay/KillZone.cs.meta b/Assets/Scripts/Gameplay/KillZone.cs.meta new file mode 100644 index 0000000..7a11166 --- /dev/null +++ b/Assets/Scripts/Gameplay/KillZone.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a6921e276aa68434aa72e38b4ad0190f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Gameplay/Objective.cs b/Assets/Scripts/Gameplay/Objective.cs index 67ee3aa..b6bca65 100644 --- a/Assets/Scripts/Gameplay/Objective.cs +++ b/Assets/Scripts/Gameplay/Objective.cs @@ -4,15 +4,33 @@ using UnityEngine; public class Objective : MonoBehaviour { + private List onObjective = new List(); + + private GameStateController GameState; // Start is called before the first frame update void Start() { - + GameState = FindObjectOfType(); + } + + private void OnTriggerEnter(Collider other) + { + PlayerController horse = other.GetComponent(); + if (horse != null) + onObjective.Add(horse); + } + + private void OnTriggerExit(Collider other) + { + PlayerController horse = other.GetComponent(); + if (horse != null) + onObjective.Remove(horse); } // Update is called once per frame void Update() { - + if(onObjective.Count >= 10) + GameState.WinState(); } } diff --git a/Assets/Scripts/Input/HerdController.cs b/Assets/Scripts/Input/HerdController.cs index b717777..37aa74d 100644 --- a/Assets/Scripts/Input/HerdController.cs +++ b/Assets/Scripts/Input/HerdController.cs @@ -31,6 +31,7 @@ public class HerdController : MonoBehaviour void Start() { + GameState = FindObjectOfType(); SpawnHerd(); }