Create random spawn

This commit is contained in:
dart 2022-04-02 23:48:20 +03:00
parent 1d13cb09df
commit 12216448ba

View File

@ -11,6 +11,9 @@ public class OverMind : MonoBehaviour
[SerializeField] private GameObject characterObject; [SerializeField] private GameObject characterObject;
[SerializeField] private float mobMoveSpeed; [SerializeField] private float mobMoveSpeed;
[SerializeField] private GameObject mobPull;
[SerializeField] private GameObject activeMobs;
private List<GameObject> _pullEnemies; private List<GameObject> _pullEnemies;
public struct MobParameters public struct MobParameters
@ -22,13 +25,16 @@ public struct MobParameters
void Start() void Start()
{ {
PreHeaterSpawn(); PreHeaterSpawn();
StartCoroutine (spawnMobsCourutine());
} }
private void PreHeaterSpawn() private void PreHeaterSpawn()
{ {
for (var i = 0; i < pullSize; i++) for (var i = 0; i < pullSize; i++)
{ {
var newMob = Instantiate(mob,transform); var newMob = Instantiate(mob,mobPull.transform);
//_mobsPull.Add(newMob);
newMob.SetActive(false);
var newMobParameters = new MobParameters var newMobParameters = new MobParameters
{ {
@ -39,8 +45,44 @@ private void PreHeaterSpawn()
newMob.GetComponent<Mob>().SetupMob(newMobParameters); newMob.GetComponent<Mob>().SetupMob(newMobParameters);
} }
} }
Vector3 GenerateRandomSpawnMobPoint()
{
var spawnBorder = 2f;
Vector3 stageDimensions = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height,0));
print(stageDimensions);
var xCoords = new Vector3(stageDimensions.x, stageDimensions.x + spawnBorder);
var yCoords = new Vector3(stageDimensions.y, stageDimensions.y + spawnBorder);
var spawnPoint = new Vector3(
Random.Range(xCoords.x, xCoords.y),
Random.Range(xCoords.x, xCoords.y),
0
);
return spawnPoint;
}
IEnumerator spawnMobsCourutine()
{
while(true)
{
Debug.Log ("OnCoroutine: "+(int)Time.time);
yield return new WaitForSeconds(1f);
var mobToSpawn = mobPull.transform.GetChild(0);
mobToSpawn.transform.position = GenerateRandomSpawnMobPoint();
mobToSpawn.parent = activeMobs.transform;
mobToSpawn.gameObject.SetActive(true);
}
}
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
} }
} }