1
0
Fork 0

Good progress on hero spawner

This commit is contained in:
Ava Gaiety Wroten 2021-07-10 22:29:45 -05:00
parent 425450a137
commit 5cc57a2086
4 changed files with 21 additions and 8 deletions

View file

@ -96,8 +96,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 847b2a28cac2e4ee49ab279670c7ac93, type: 3} m_Script: {fileID: 11500000, guid: 847b2a28cac2e4ee49ab279670c7ac93, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
speed: 3 speed: 6
timeToMove: 3 timeToMove: 2
--- !u!61 &8641468276557857728 --- !u!61 &8641468276557857728
BoxCollider2D: BoxCollider2D:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View file

@ -170,6 +170,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
hero: {fileID: 3021765642569073806, guid: 56983197fa2e04a4c8d44100f0ef42b4, type: 3} hero: {fileID: 3021765642569073806, guid: 56983197fa2e04a4c8d44100f0ef42b4, type: 3}
timeRemaining: 3 timeRemaining: 3
numberOfHeros: 2
--- !u!1 &519420028 --- !u!1 &519420028
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -324,8 +325,8 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1027402149} m_GameObject: {fileID: 1027402149}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -5.5937815, y: 0.20069107, z: 0} m_LocalPosition: {x: -5.6738, y: 0.214, z: 0}
m_LocalScale: {x: 7.1661797, y: 10.121618, z: 1} m_LocalScale: {x: 7.3259854, y: 10.095302, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 569685894} m_Father: {fileID: 569685894}
m_RootOrder: 0 m_RootOrder: 0

View file

@ -6,8 +6,10 @@ public class HeroSpawner : MonoBehaviour
{ {
public GameObject hero; public GameObject hero;
public float timeRemaining = 3; public float timeRemaining = 3;
public int numberOfHeros = 2;
private float originalTimeRemaining; private float originalTimeRemaining;
private float[] yPositions = new float[]{4.0f, 2.0f, 0.0f, -2.0f, -4.0f}; private float[] yPositions = new float[]{4.0f, 2.0f, 0.0f, -2.0f, -4.0f};
private int numberOfYPositions = 5;
void Start() void Start()
{ {
@ -21,14 +23,25 @@ public class HeroSpawner : MonoBehaviour
timeRemaining -= Time.deltaTime; timeRemaining -= Time.deltaTime;
} else } 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 heroStartingX = -3.0f;
float heroStartingY = 0.0f; /* float heroStartingY = yPositions[Random.Range(0, numberOfYPositions - 1)]; */
Vector2 heroStartingPosition = new Vector2(heroStartingX, heroStartingY); Vector2 heroStartingPosition = new Vector2(heroStartingX, heroStartingY);
timeRemaining = originalTimeRemaining; timeRemaining = originalTimeRemaining;
GameObject spawnedHero = Instantiate(hero, heroStartingPosition, Quaternion.identity); GameObject spawnedHero = Instantiate(hero, heroStartingPosition, Quaternion.identity);

View file

@ -1 +0,0 @@
81535