Hello,
*Excuse my rusty English
I'm creating a 2D Game and trying to create a random moving enemy, and the code works fine in small numbers.. but when i enter more than 50 enemies the game become very heavy! and i want to create more than 50!! is there another solutions?
using UnityEngine;
using System.Collections;
public class CreateRandomEnemy : MonoBehaviour {
public GameObject enemyPrefab;
public float numEnemies;
public float xMin = 6F;
public float xMax = 50F;
public float yMin = 2F;
public float yMax = -8F;
void Start () {
GameObject newParent = GameObject.Find("Scripts");
for (int i = 0; i < numEnemies; i++)
{
Vector3 newPos = new Vector3(Random.Range(xMin, xMax), Random.Range(yMin, yMax), 0);
GameObject octo = Instantiate(enemyPrefab, newPos, Quaternion.identity) as GameObject;
octo.transform.parent = newParent.transform;
}
}
}
↧