private void create_item() { Vector3 item_position; if (!this.last_item.is_created) { item_position = this.player.transform.position; item_position.x += BLOCK_WIDTH * ((float)BLOCK_NUM_IN_SCREEN / 2.0f); item_position.y = 3; } else { item_position = this.last_item.position; } item_position.y = level_control.current_block.height * BLOCK_HEIGHT + 3; ItemBlockType currentType = level_control.current_item.item_type; if (currentType != ItemBlockType.Space) { item_creator.create_item(currentType, item_position); last_item.is_created = true; } level_control.current_item.current_count++; item_position.x += BLOCK_WIDTH; last_item.position = item_position; }
public void create_item(ItemBlockType type, Vector3 item_position) { GameObject prefab = null; if (FindPrefabFromType(type, out prefab)) { GameObject go = GameObject.Instantiate(prefab); go.transform.position = item_position; } }
bool FindPrefabFromType(ItemBlockType type, out GameObject prefab) { prefab = null; foreach (var item in itemPrefabs) { if (item.type == type) { prefab = item.prefab; return(true); } } return(false); }