void Start() { int weaponType = 0; for (int i = 0; i < numberOfSoldiersToCreate; i++) { //Make visual representations of the soldiers GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube); go.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f); SoldierGameObject soldierGameObject = go.AddComponent <SoldierGameObject>(); soldierGameObject.Create((WeaponType)weaponType); go.name = ((WeaponType)weaponType).ToString(); int startHealth = SoldierFlyweightFactory.Soldier((WeaponType)weaponType).Stats.MaxHealth; soldierGameObject.health = startHealth; float x = Random.Range(minPosition.x, maxPosition.x); float y = Random.Range(minPosition.y, maxPosition.y); go.transform.position = new Vector3(x, 0.45f * go.transform.localScale.y, y); go.GetComponent <MeshRenderer>().material.color = SoldierFlyweightFactory.Soldier((WeaponType)weaponType).GetColor(startHealth); weaponType = (weaponType + 1) % 3; } Debug.LogFormat("Created {0} soldiers. Flyweight count: {1}", numberOfSoldiersToCreate, SoldierFlyweightFactory.SoldierCount); }
public void Create(WeaponType weaponType) { soldier = SoldierFlyweightFactory.Soldier(weaponType); gameObject.AddComponent <BoxCollider>(); }