// Use this for initialization void Start() { gameManager = GameObject.Find("GameManager").GetComponent <GameManager>(); dataController = GameObject.Find("DataController").GetComponent <DataController>(); honeyScore = GameObject.Find("HoneyScore").GetComponent <HoneyScore>(); honeyCurrency = GameObject.Find("HoneyCurrency").GetComponent <HoneyCurrency>(); isEmpty = true; emptyTime = 0f; fullForTime = 0f; foreach (Transform child in transform) { if (child.gameObject.name == "honeyEmptyButton") { honeyEmpty = child.gameObject.GetComponent <Image>(); } else if (child.gameObject.name == "honeyFullImage") { honeyFull = child.gameObject.GetComponent <Image>(); } } readyTime = 10f; // the units surrounding this one FillotherSix(); //pushSound = GetComponent<AudioSource>(); pushSound = GameObject.Find("SoundsAudio").GetComponent <AudioSource>(); }
// TODO on scene load ? void Update() { // done here and not in LoadGameData since the scene name must first be loaded (.....) if (!dataLoaded && loadedData != null && SceneManager.GetActiveScene().name == "GameScene") { dataLoaded = true; // so this wont be repeated // then load from file // get the objects that data will be loaded into //GameObject[] unitObjects = GameObject.FindGameObjectsWithTag("honeyUnit"); honeyScore = GameObject.Find("HoneyScore").GetComponent <HoneyScore>(); honeyCurrency = GameObject.Find("HoneyCurrency").GetComponent <HoneyCurrency>(); for (int i = 0; i < loadedData.units.Length; i++) { // get honey unit and its name GameObject temp = GameObject.Find(loadedData.units[i].name); HoneyHandler honeyHandler = temp.GetComponent <HoneyHandler>(); string currName = loadedData.units[i].honeyFullImage; // fill the unit's HoneyHandler with data from honeyDict about the honey type honeyHandler.fillTime = honeyDict[currName].time; honeyHandler.points = honeyDict[currName].points; honeyHandler.price = honeyDict[currName].price; honeyHandler.honeyEmpty.sprite = Resources.Load <Sprite>("Sprites/" + honeyDict[currName].emptySprite); honeyHandler.honeyFull.sprite = Resources.Load <Sprite>("Sprites/" + honeyDict[currName].fullSprite); honeyHandler.isActivated = loadedData.units[i].isActivated; if (!honeyHandler.isActivated) { // change sprite to the empty one and deactivate the gameobject honeyHandler.honeyEmpty.sprite = Resources.Load <Sprite>("Sprites/hexhoneyADD"); temp.SetActive(false); } honeyHandler.honeyEmpty.enabled = true; honeyHandler.honeyFull.enabled = false; } honeyScore.harvestedHoney = loadedData.honeyScore; honeyCurrency.currency = loadedData.honeyCurrency; //musicSource.volume = loadedData.musicOn; // TODO won't work since data is loaded after music } }