From 230a654a9fc959b7156fda00e8d9d552e4fd5ccd Mon Sep 17 00:00:00 2001 From: NickFowler Date: Sat, 1 Feb 2020 20:09:34 +1100 Subject: [PATCH 1/2] Added basic game states and objective --- Assets/Scenes/SampleScene.unity | 217 +++++++++++++++++- Assets/Scripts/Gameplay.meta | 8 + .../Scripts/Gameplay/GameStateController.cs | 28 +++ .../Gameplay/GameStateController.cs.meta | 11 + Assets/Scripts/Gameplay/Objective.cs | 18 ++ Assets/Scripts/Gameplay/Objective.cs.meta | 11 + Assets/Scripts/Input/HerdController.cs | 7 + 7 files changed, 290 insertions(+), 10 deletions(-) create mode 100644 Assets/Scripts/Gameplay.meta create mode 100644 Assets/Scripts/Gameplay/GameStateController.cs create mode 100644 Assets/Scripts/Gameplay/GameStateController.cs.meta create mode 100644 Assets/Scripts/Gameplay/Objective.cs create mode 100644 Assets/Scripts/Gameplay/Objective.cs.meta diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 3dbb2f8..6540f4f 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -208,12 +208,42 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 33826417} m_LocalRotation: {x: 0, y: -0.7071068, z: 0, w: 0.7071068} - m_LocalPosition: {x: -21.69, y: -1.012, z: 20.28} + m_LocalPosition: {x: -21.69, y: 5.288, z: 20.28} m_LocalScale: {x: 15.892654, y: 14.241516, z: 1} m_Children: [] m_Father: {fileID: 0} m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: -90, z: 0} +--- !u!1 &338695192 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 338695193} + m_Layer: 0 + m_Name: CameraTarget + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &338695193 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 338695192} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 1457452761} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &380641380 GameObject: m_ObjectHideFlags: 0 @@ -301,8 +331,8 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 380641380} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0.8334109, y: -6.424332, z: 13.56534} - m_LocalScale: {x: 46.966, y: 1, z: 56.905} + m_LocalPosition: {x: 0.8334109, y: 0, z: 13.56534} + m_LocalScale: {x: 403.69156, y: 1, z: 291.63242} m_Children: [] m_Father: {fileID: 0} m_RootOrder: 3 @@ -394,7 +424,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 383575962} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: -5.23, z: 7.37} + m_LocalPosition: {x: 0, y: 1.0700002, z: 7.37} m_LocalScale: {x: 5, y: 5, z: 5} m_Children: [] m_Father: {fileID: 0} @@ -579,7 +609,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 778362041} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0.8334109, y: -1.012, z: 27.1} + m_LocalPosition: {x: 0.8334109, y: 5.288, z: 27.1} m_LocalScale: {x: 44.013, y: 14.241516, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -672,7 +702,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 903473255} m_LocalRotation: {x: -0.23348022, y: -0, z: -0, w: 0.97236156} - m_LocalPosition: {x: 9.03, y: -5.55, z: 0} + m_LocalPosition: {x: 9.03, y: 0.75, z: 0} m_LocalScale: {x: 7.4761, y: 1, z: 4.4214} m_Children: [] m_Father: {fileID: 0} @@ -689,6 +719,7 @@ GameObject: - component: {fileID: 963194228} - component: {fileID: 963194227} - component: {fileID: 963194226} + - component: {fileID: 963194229} m_Layer: 0 m_Name: Main Camera m_TagString: MainCamera @@ -728,7 +759,7 @@ Camera: width: 1 height: 1 near clip plane: 0.3 - far clip plane: 1000 + far clip plane: 200 field of view: 60 orthographic: 0 orthographic size: 5 @@ -761,6 +792,63 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 45, y: 0, z: 0} +--- !u!114 &963194229 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 963194225} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 49812763c430a0f4cb0f5e99a203f1ad, type: 3} + m_Name: + m_EditorClassIdentifier: + target: {fileID: 338695192} + camHeight: 25 +--- !u!1 &1065404629 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1065404631} + - component: {fileID: 1065404630} + m_Layer: 0 + m_Name: Game State Controller + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1065404630 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1065404629} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 24cee4f9f3aafc34fb344ec4b026a3ae, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!4 &1065404631 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1065404629} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 28.266376, y: -59.30715, z: 117.915985} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 9 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1457452758 GameObject: m_ObjectHideFlags: 0 @@ -823,10 +911,11 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: Prefab: {fileID: 7371939184051845554, guid: f5c2c9744b6f46e4e95ca41ab1d8d560, type: 3} - HerdCount: 100 + HerdCount: 20 SpawnPoint: {fileID: 0} WaitTime: 0.2 - Centre: {fileID: 0} + Centre: {fileID: 338695193} + GameState: {fileID: 0} --- !u!4 &1457452761 Transform: m_ObjectHideFlags: 0 @@ -837,7 +926,115 @@ Transform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] + m_Children: + - {fileID: 338695193} m_Father: {fileID: 0} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1983113841 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1983113846} + - component: {fileID: 1983113845} + - component: {fileID: 1983113844} + - component: {fileID: 1983113843} + - component: {fileID: 1983113842} + m_Layer: 0 + m_Name: Objective + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1983113842 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1983113841} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7ae3efa00f9dbc5458f2601705870f17, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!136 &1983113843 +CapsuleCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1983113841} + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_Enabled: 1 + m_Radius: 0.5000001 + m_Height: 2 + m_Direction: 1 + m_Center: {x: 0.000000059604645, y: 0, z: -0.00000008940697} +--- !u!23 &1983113844 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1983113841} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!33 &1983113845 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1983113841} + m_Mesh: {fileID: 10206, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &1983113846 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1983113841} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -71.9, y: 1.22, z: 0} + m_LocalScale: {x: 10, y: 1, z: 10} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 8 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/Scripts/Gameplay.meta b/Assets/Scripts/Gameplay.meta new file mode 100644 index 0000000..e7796cd --- /dev/null +++ b/Assets/Scripts/Gameplay.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4e4e17e5beebfb746ac8d3e8d10c137b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Gameplay/GameStateController.cs b/Assets/Scripts/Gameplay/GameStateController.cs new file mode 100644 index 0000000..6f95814 --- /dev/null +++ b/Assets/Scripts/Gameplay/GameStateController.cs @@ -0,0 +1,28 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class GameStateController : MonoBehaviour +{ + + // Start is called before the first frame update + void Start() + { + } + + public void WinState() + { + Debug.Log("You win!"); + } + + public void LoseState() + { + Debug.Log("You lose!"); + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/Gameplay/GameStateController.cs.meta b/Assets/Scripts/Gameplay/GameStateController.cs.meta new file mode 100644 index 0000000..c31d2ba --- /dev/null +++ b/Assets/Scripts/Gameplay/GameStateController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 24cee4f9f3aafc34fb344ec4b026a3ae +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 new file mode 100644 index 0000000..67ee3aa --- /dev/null +++ b/Assets/Scripts/Gameplay/Objective.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Objective : MonoBehaviour +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/Assets/Scripts/Gameplay/Objective.cs.meta b/Assets/Scripts/Gameplay/Objective.cs.meta new file mode 100644 index 0000000..3eb3ff7 --- /dev/null +++ b/Assets/Scripts/Gameplay/Objective.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7ae3efa00f9dbc5458f2601705870f17 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Input/HerdController.cs b/Assets/Scripts/Input/HerdController.cs index 800986b..b374e3d 100644 --- a/Assets/Scripts/Input/HerdController.cs +++ b/Assets/Scripts/Input/HerdController.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using UnityEngine; using UnityEngine.InputSystem; @@ -26,6 +27,8 @@ public class HerdController : MonoBehaviour private List Herd; private Vector2 recievedInput; + public GameStateController GameState; + void Start() { SpawnHerd(); @@ -108,6 +111,10 @@ public class HerdController : MonoBehaviour if (Centre != null) Centre.position = Herd.Aggregate(new Vector3(0, 0, 0), (s, v) => s + v.transform.position) / (float)Herd.Count; + + if (Herd.Count.Equals(0)) + GameState.LoseState(); + } public void RemoveHorse(PlayerController horse) From 60d9ce6eef3a3134532df3120b30b349da9c5e06 Mon Sep 17 00:00:00 2001 From: NickFowler Date: Sat, 1 Feb 2020 20:50:48 +1100 Subject: [PATCH 2/2] 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(); }