Question by
Elganif · May 22, 2018 at 04:51 AM ·
gameobjectprefab-instancerandomization
How do create multiple semi unique objects form a singular prefab or template?
I want to create many different enemies from a single source prefab or template to build randomly generated armies of 10 to 15 different enemy types from one source prefab and then just add the sprite and a stat set at random.
Is there a better way to pull a prefab into the game world than instantiate that would allow the resulting objects to be edited individually? or an alternative to prefabs that could what I want?
Comment
Best Answer
Answer by Elganif · May 24, 2018 at 02:03 AM
Figured it out, i put the script that sets the sprite component onto the prefab itself instead of in the script that created the object a line like this and each object sets its own sprite
void Start () {
this.gameObject.GetComponent<SpriteRenderer>().sprite = this.GetComponentInParent<MobSpawning>().spawnNormalEnemy();
}
getMinionSprite returns the sprite I want the enemy to look like from