From 5cc57a2086c328f2eb21e0f8d4551fc84751eeea Mon Sep 17 00:00:00 2001 From: Ava Gaiety Wroten Date: Sat, 10 Jul 2021 22:29:45 -0500 Subject: [PATCH] Good progress on hero spawner --- Assets/Prefabs/Hero.prefab | 4 ++-- Assets/Scenes/Gameplay.unity | 5 +++-- Assets/Scripts/HeroSpawner.cs | 19 ++++++++++++++++--- tags.lock | 1 - 4 files changed, 21 insertions(+), 8 deletions(-) delete mode 100644 tags.lock diff --git a/Assets/Prefabs/Hero.prefab b/Assets/Prefabs/Hero.prefab index 907fc5b..c9581ed 100644 --- a/Assets/Prefabs/Hero.prefab +++ b/Assets/Prefabs/Hero.prefab @@ -96,8 +96,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 847b2a28cac2e4ee49ab279670c7ac93, type: 3} m_Name: m_EditorClassIdentifier: - speed: 3 - timeToMove: 3 + speed: 6 + timeToMove: 2 --- !u!61 &8641468276557857728 BoxCollider2D: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/Gameplay.unity b/Assets/Scenes/Gameplay.unity index f60ff5b..9642afa 100644 --- a/Assets/Scenes/Gameplay.unity +++ b/Assets/Scenes/Gameplay.unity @@ -170,6 +170,7 @@ MonoBehaviour: m_EditorClassIdentifier: hero: {fileID: 3021765642569073806, guid: 56983197fa2e04a4c8d44100f0ef42b4, type: 3} timeRemaining: 3 + numberOfHeros: 2 --- !u!1 &519420028 GameObject: m_ObjectHideFlags: 0 @@ -324,8 +325,8 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1027402149} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -5.5937815, y: 0.20069107, z: 0} - m_LocalScale: {x: 7.1661797, y: 10.121618, z: 1} + m_LocalPosition: {x: -5.6738, y: 0.214, z: 0} + m_LocalScale: {x: 7.3259854, y: 10.095302, z: 1} m_Children: [] m_Father: {fileID: 569685894} m_RootOrder: 0 diff --git a/Assets/Scripts/HeroSpawner.cs b/Assets/Scripts/HeroSpawner.cs index ad9a1c8..e7b9fb4 100644 --- a/Assets/Scripts/HeroSpawner.cs +++ b/Assets/Scripts/HeroSpawner.cs @@ -6,8 +6,10 @@ public class HeroSpawner : MonoBehaviour { public GameObject hero; public float timeRemaining = 3; + public int numberOfHeros = 2; private float originalTimeRemaining; private float[] yPositions = new float[]{4.0f, 2.0f, 0.0f, -2.0f, -4.0f}; + private int numberOfYPositions = 5; void Start() { @@ -21,14 +23,25 @@ public class HeroSpawner : MonoBehaviour timeRemaining -= Time.deltaTime; } else { - SpawnHero(); + bool[] spawnedPositions = new bool[]{false, false, false, false, false}; + for(int index = 0; index < numberOfHeros; index++) + { + int randomY; + do + { + randomY = Random.Range(0, numberOfYPositions - 1); + } while(spawnedPositions[randomY]); + spawnedPositions[randomY] = true; + + SpawnHero(yPositions[randomY]); + } } } - void SpawnHero() + void SpawnHero(float heroStartingY) { float heroStartingX = -3.0f; - float heroStartingY = 0.0f; + /* float heroStartingY = yPositions[Random.Range(0, numberOfYPositions - 1)]; */ Vector2 heroStartingPosition = new Vector2(heroStartingX, heroStartingY); timeRemaining = originalTimeRemaining; GameObject spawnedHero = Instantiate(hero, heroStartingPosition, Quaternion.identity); diff --git a/tags.lock b/tags.lock deleted file mode 100644 index 9c48c6d..0000000 --- a/tags.lock +++ /dev/null @@ -1 +0,0 @@ -81535