From 1d39db5325d56b818032ca78c0dcf07ffe2f9211 Mon Sep 17 00:00:00 2001 From: Lorenzo Balugani Date: Mon, 13 Aug 2018 15:26:10 +0200 Subject: [PATCH] Add winner --- Assets/Prefabs/Time left.prefab | 105 +++++++++++++++++ Assets/Prefabs/Time left.prefab.meta | 8 ++ Assets/Scenes/Results.unity | 161 ++++++++++++++++++++++++++- Assets/Scripts/Countdown.cs | 20 +++- Assets/Scripts/FishSpawnerEnding.cs | 7 ++ 5 files changed, 296 insertions(+), 5 deletions(-) create mode 100644 Assets/Prefabs/Time left.prefab create mode 100644 Assets/Prefabs/Time left.prefab.meta diff --git a/Assets/Prefabs/Time left.prefab b/Assets/Prefabs/Time left.prefab new file mode 100644 index 0000000..f2d0182 --- /dev/null +++ b/Assets/Prefabs/Time left.prefab @@ -0,0 +1,105 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1001 &100100000 +Prefab: + m_ObjectHideFlags: 1 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: [] + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 0} + m_RootGameObject: {fileID: 1365020258240812} + m_IsPrefabAsset: 1 +--- !u!1 &1365020258240812 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 6 + m_Component: + - component: {fileID: 224434015513733384} + - component: {fileID: 222494154202823632} + - component: {fileID: 114654271599845820} + - component: {fileID: 114128334027664462} + m_Layer: 5 + m_Name: Time left + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &114128334027664462 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1365020258240812} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 80f6e912b74c1744d83aedb0e365fa93, type: 3} + m_Name: + m_EditorClassIdentifier: + startingTime: 240 + script: {fileID: 0} + nave1: {fileID: 0} + nave2: {fileID: 0} + nave3: {fileID: 0} +--- !u!114 &114654271599845820 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1365020258240812} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} + m_RaycastTarget: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + m_FontData: + m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + m_FontSize: 300 + m_FontStyle: 0 + m_BestFit: 0 + m_MinSize: 10 + m_MaxSize: 300 + m_Alignment: 0 + m_AlignByGeometry: 0 + m_RichText: 1 + m_HorizontalOverflow: 0 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: X:XX +--- !u!222 &222494154202823632 +CanvasRenderer: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1365020258240812} + m_CullTransparentMesh: 0 +--- !u!224 &224434015513733384 +RectTransform: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1365020258240812} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 0.15, y: 0.15, z: 0.15} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 10, y: -5} + m_SizeDelta: {x: 1377.9, y: 372.7} + m_Pivot: {x: 0, y: 1} diff --git a/Assets/Prefabs/Time left.prefab.meta b/Assets/Prefabs/Time left.prefab.meta new file mode 100644 index 0000000..9a2033f --- /dev/null +++ b/Assets/Prefabs/Time left.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: de8e91ffd22ee45459f4d929276aab08 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 100100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Results.unity b/Assets/Scenes/Results.unity index 1aec93d..b78a7b4 100644 --- a/Assets/Scenes/Results.unity +++ b/Assets/Scenes/Results.unity @@ -478,6 +478,7 @@ MonoBehaviour: fish: {fileID: 1615301965237016, guid: 3b07c51a898a8e342b3d0236ca47bf8c, type: 2} sea: {fileID: 1883986867} punteggio: {fileID: 1625724831} + winner: {fileID: 1633702437} --- !u!1 &1497958429 GameObject: m_ObjectHideFlags: 0 @@ -564,7 +565,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 543.2, y: 240} + m_AnchoredPosition: {x: 473.6, y: 240} m_SizeDelta: {x: 160, y: 30} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1625724831 @@ -593,7 +594,7 @@ MonoBehaviour: m_BestFit: 1 m_MinSize: 2 m_MaxSize: 40 - m_Alignment: 0 + m_Alignment: 1 m_AlignByGeometry: 0 m_RichText: 1 m_HorizontalOverflow: 0 @@ -607,6 +608,81 @@ CanvasRenderer: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 1625724829} m_CullTransparentMesh: 0 +--- !u!1 &1633702435 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1633702436} + - component: {fileID: 1633702438} + - component: {fileID: 1633702437} + m_Layer: 5 + m_Name: wins + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1633702436 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1633702435} + 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: 2050323200} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 472.59998, y: 144.8} + m_SizeDelta: {x: 160, y: 30} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1633702437 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1633702435} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} + m_RaycastTarget: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + m_FontData: + m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + m_FontSize: 14 + m_FontStyle: 0 + m_BestFit: 1 + m_MinSize: 10 + m_MaxSize: 40 + m_Alignment: 1 + m_AlignByGeometry: 0 + m_RichText: 1 + m_HorizontalOverflow: 0 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: wins! +--- !u!222 &1633702438 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1633702435} + m_CullTransparentMesh: 0 --- !u!1 &1761400630 GameObject: m_ObjectHideFlags: 0 @@ -670,11 +746,11 @@ Prefab: m_Modifications: - target: {fileID: 4955254497044876, guid: 343a89599f7365845937eb14b4669b20, type: 2} propertyPath: m_LocalPosition.x - value: -0.08 + value: 0.005 objectReference: {fileID: 0} - target: {fileID: 4955254497044876, guid: 343a89599f7365845937eb14b4669b20, type: 2} propertyPath: m_LocalPosition.y - value: 18.1 + value: 19.002 objectReference: {fileID: 0} - target: {fileID: 4955254497044876, guid: 343a89599f7365845937eb14b4669b20, type: 2} propertyPath: m_LocalPosition.z @@ -724,6 +800,81 @@ GameObject: m_CorrespondingSourceObject: {fileID: 1259758189242624, guid: 4dc0408b236da9847b1c799161bbd70a, type: 2} m_PrefabInternal: {fileID: 339374824} +--- !u!1 &2030790936 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2030790937} + - component: {fileID: 2030790939} + - component: {fileID: 2030790938} + m_Layer: 5 + m_Name: winner + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &2030790937 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2030790936} + 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: 2050323200} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 472.6, y: 184.9} + m_SizeDelta: {x: 160, y: 30} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &2030790938 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2030790936} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} + m_RaycastTarget: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + m_FontData: + m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + m_FontSize: 14 + m_FontStyle: 0 + m_BestFit: 1 + m_MinSize: 10 + m_MaxSize: 40 + m_Alignment: 1 + m_AlignByGeometry: 0 + m_RichText: 1 + m_HorizontalOverflow: 0 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: +--- !u!222 &2030790939 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2030790936} + m_CullTransparentMesh: 0 --- !u!1 &2050323196 GameObject: m_ObjectHideFlags: 0 @@ -811,6 +962,8 @@ RectTransform: m_Children: - {fileID: 824294109} - {fileID: 1625724830} + - {fileID: 2030790937} + - {fileID: 1633702436} m_Father: {fileID: 0} m_RootOrder: 7 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/Scripts/Countdown.cs b/Assets/Scripts/Countdown.cs index 7b94320..c80bc7f 100644 --- a/Assets/Scripts/Countdown.cs +++ b/Assets/Scripts/Countdown.cs @@ -8,6 +8,9 @@ public class Countdown : MonoBehaviour { public float startingTime = 500f; public GameObject script; + public GameObject nave1; + public GameObject nave2; + public GameObject nave3; private float currentTime = 500f; private Text timerText; @@ -27,11 +30,26 @@ public class Countdown : MonoBehaviour { void TheEnd() { - FishCatcher presi; + FishCatcher presi, ai1, ai2, ai3; presi = script.GetComponent(); + ai1 = nave1.GetComponent(); + ai2 = nave2.GetComponent(); + ai3 = nave3.GetComponent(); + int[] punteggi = { ai1.fishCaught, ai2.fishCaught, ai3.fishCaught}; + int punteggio = 0; + string vincitore = "Player"; + foreach ( int punteggioai in punteggi) + { + if(punteggioai > punteggio) + { + vincitore = "A.I."; + } + } int score = presi.fishCaught; Debug.Log(score); + Debug.Log(vincitore); PlayerPrefs.SetInt("player_score", score); + PlayerPrefs.SetString("winner", vincitore); SceneManager.LoadSceneAsync("Results", LoadSceneMode.Single); } } diff --git a/Assets/Scripts/FishSpawnerEnding.cs b/Assets/Scripts/FishSpawnerEnding.cs index 9113281..830d28b 100644 --- a/Assets/Scripts/FishSpawnerEnding.cs +++ b/Assets/Scripts/FishSpawnerEnding.cs @@ -11,14 +11,17 @@ public class FishSpawnerEnding : MonoBehaviour public GameObject fish; public GameObject sea; public Text punteggio; + public Text winner; private float timeToSpawn; private int toSpawn; private int spawned = 0; + private string vincitore = ""; void Start() { timeToSpawn = Random.Range(spawnTime - randomFactor, spawnTime + randomFactor); toSpawn = PlayerPrefs.GetInt("player_score"); + vincitore = PlayerPrefs.GetString("winner"); } void Update() @@ -33,5 +36,9 @@ public class FishSpawnerEnding : MonoBehaviour spawned++; punteggio.text = spawned.ToString(); } + if (spawned >= toSpawn) + { + winner.text = vincitore; + } } }