void spawnObjects(bool start) { Vector3 userPos = player.transform.position; if (objects.Count <= Attributes.maxObjects) { float minX, minZ, maxX, maxZ; minX = userPos.x - Attributes.halfTileX * Attributes.planeSize; maxX = userPos.x + Attributes.halfTileX * Attributes.planeSize; minZ = userPos.z - Attributes.halfTileZ * Attributes.planeSize; maxZ = userPos.z + Attributes.halfTileZ * Attributes.planeSize; float posX, posZ, posY; for (int i = 0; i < Attributes.maxObjects - objects.Count; i++) { posX = Random.Range(minX, maxX); posY = Random.Range(7, 12); posZ = Random.Range(minZ, maxZ); createObject(start, new Vector3(posX, posY, posZ), DC_Object.intToEnum(Random.Range(0, 4))); } } }
void createObject(bool start, Vector3 pos, DC_Object.ObjectType type) { switch (type) { case DC_Object.ObjectType.THROWABLE: GameObject th_o = (GameObject)Instantiate(throwableObjects[Random.Range(0, throwableObjects.Length)], pos, Quaternion.identity); th_o.gameObject.tag = "Throwable"; th_o.gameObject.transform.SetParent(objectParent.transform); if (start) { th_o.gameObject.AddComponent <randomTexture>(); th_o.gameObject.GetComponent <randomTexture>().enabled = true; } else { th_o.gameObject.AddComponent <randomTexture>(); th_o.gameObject.GetComponent <randomTexture>().enabled = true; } DC_Object th_newObject = new DC_Object(th_o, type); objects.Add(th_newObject); break; case DC_Object.ObjectType.FREE: GameObject f_o = (GameObject)Instantiate(freeObjects[Random.Range(0, freeObjects.Length)], pos, Quaternion.identity); f_o.gameObject.tag = "free"; f_o.gameObject.transform.SetParent(objectParent.transform); if (start) { f_o.gameObject.AddComponent <randomTextureStart>(); f_o.gameObject.GetComponent <randomTextureStart>().enabled = true; } else { f_o.gameObject.AddComponent <randomTexture>(); f_o.gameObject.GetComponent <randomTexture>().enabled = true; } DC_Object f_newObject = new DC_Object(f_o, type); free.Add(f_newObject); break; case DC_Object.ObjectType.ANIMATED: GameObject a_o = (GameObject)Instantiate(animatedObjects[Random.Range(0, animatedObjects.Length)], pos, Quaternion.identity); a_o.gameObject.tag = "animated"; a_o.gameObject.transform.SetParent(objectParent.transform); if (start) { a_o.gameObject.AddComponent <randomTextureStart>(); a_o.gameObject.GetComponent <randomTextureStart>().enabled = true; } else { a_o.gameObject.AddComponent <randomTexture>(); a_o.gameObject.GetComponent <randomTexture>().enabled = true; } addAnimation(a_o); DC_Object a_newObject = new DC_Object(a_o, type); objects.Add(a_newObject); break; case DC_Object.ObjectType.CHARACTER: GameObject c_o = (GameObject)Instantiate(characters[Random.Range(0, characters.Length)], new Vector3(pos.x, Random.Range(10, 40), pos.z), Quaternion.identity); c_o.gameObject.tag = "character"; c_o.gameObject.transform.SetParent(objectParent.transform); if (start) { c_o.gameObject.AddComponent <randomTextureStart>(); c_o.gameObject.GetComponent <randomTextureStart>().enabled = true; } else { c_o.gameObject.AddComponent <randomTexture>(); c_o.gameObject.GetComponent <randomTexture>().enabled = true; } c_o.gameObject.AddComponent <CharacterWander>(); c_o.gameObject.GetComponent <CharacterWander>().enabled = true; DC_Object c_newObject = new DC_Object(c_o, type); objects.Add(c_newObject); break; case DC_Object.ObjectType.PANEL: GameObject p_o = (GameObject)Instantiate(panels[Random.Range(0, panels.Length)], pos, Quaternion.Euler(90, Random.Range(0, 180), 0)); p_o.gameObject.tag = "panel"; p_o.gameObject.transform.SetParent(objectParent.transform); if (start) { p_o.gameObject.AddComponent <randomTextureStart>(); p_o.gameObject.GetComponent <randomTextureStart>().enabled = true; } else { p_o.gameObject.AddComponent <randomTexture>(); p_o.gameObject.GetComponent <randomTexture>().enabled = true; } DC_Object p_newObject = new DC_Object(p_o, type); objects.Add(p_newObject); break; default: break; } }