Good progress on hero spawner
This commit is contained in:
parent
425450a137
commit
5cc57a2086
4 changed files with 21 additions and 8 deletions
4
Assets/Prefabs/Hero.prefab
generated
4
Assets/Prefabs/Hero.prefab
generated
|
@ -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
|
||||
|
|
5
Assets/Scenes/Gameplay.unity
generated
5
Assets/Scenes/Gameplay.unity
generated
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
81535
|
Loading…
Add table
Reference in a new issue