- Home /
Instantiating GameObjects(enemies) far away from each other
Any idea how i can instantiate 2 gameobjects further away from each other? the player position not included...for example i have such a script:
float timer; public GameObject marker; Transform markerPosition; void Start(){ timer = 10f; } void Update(){ timer -= Time.deltaTime; if(timer <= 0f){ EnemyMarker(); timer = 10f; } } void EnemyMarker(){ float x = Random.Range(1f,5f); float y = Random.Range(1f,5f); markerPosition = new Vector3(x,y,0f); Instantiate(marker, markerPosition, Quaternion.identity); StartCoroutine("instantiateEnemy"); } IEnumerator instantiateEnemy(){ yield return new WaitForSeconds(1.5f); Instantiate(enemy, marker.transform.position, Quaternion.identity); Destroy(marker.gameObject); }
This is just an example i wrote just now, not sure if it runs, buts its to get the idea accross...now my target is to instantiate 2,then 3, then 4 markers and enemies at the same time but further away from each other. Number of enemies will be incremented by a certain code based on the points the player has earned