//This method spawns new collectables randomly to all scenes if all objects are collected public void CheckForNewSpawns(object sender, BGEventArgsAnyEntity args) { //there are still some collectables if (BGE_Collectable.CountEntities > 0) { return; } //ok, we gathered all objects- lets spawn new ones BGE_Scene.ForEachEntity(scene => { //number of collectables for one scene var count = Random.Range(3, 6); for (var i = 0; i < count; i++) { //nested meta has utility method, which auto assign new collectable to owner entity (scene) var newCollectable = BGE_Collectable.NewEntity(scene); //set gold newCollectable.f_gold = Random.Range(1, 10); //bounds determines scene's frontiers var bounds = scene.f_bounds; //set position newCollectable.f_position = new Vector3(Random.Range(bounds.min.x, bounds.max.x), bounds.center.y, Random.Range(bounds.min.z, bounds.max.z)); //set type newCollectable.f_type = BGE_CollectableType.GetEntity(Random.Range(0, BGE_CollectableType.CountEntities)); } }); //spawn GameObjects for current scene Spawn(); }
//this method is called before saving void BGAddonSaveLoad.BeforeSaveReciever.OnBeforeSave() { //save current position , rotation and scene to the database m_position = transform.position; m_rotation = transform.rotation; m_scene = BGE_Scene.FindEntity(scene => string.Equals(scene.Name, SceneManager.GetActiveScene().name)); }