public void ClickBuy() { if (!isEnable) { int money = manager.GetComponent <ScoreManager>().money; if (money >= price) { money -= price; PlayerPrefs.SetInt("SaveMoney", money); PlayerPrefs.Save(); isEnable = true; PlayerPrefs.SetInt("BuyItemGround" + id, 1); PlayerPrefs.Save(); } ReloadItem(); } else { // Change ground generator = GameObject.Find("Generator").GetComponent <GenerateMap>(); GameObject[] grounds = GameObject.FindGameObjectsWithTag("Ground"); // Start material for (int i = 0; i < grounds.Length; i++) { GameObject.FindGameObjectsWithTag("Ground")[i].GetComponentInChildren <Renderer>().material = mainMaterial; } for (int i = 0; i < grounds.Length; i += 2) { GameObject.FindGameObjectsWithTag("Ground")[i].GetComponentInChildren <Renderer>().material = additionalMaterial; } // Update material generator.GetComponent <GenerateMap>().mainMaterial = mainMaterial; generator.GetComponent <GenerateMap>().additionalMaterial = additionalMaterial; generator.GetComponent <GenerateMap>().ReMesh(generator.GetComponent <GenerateMap>().firstGround); PlayerPrefs.SetInt("LastItemGround", id); PlayerPrefs.Save(); } }
public void ReplacePlayer() { GameObject playerLast = GameObject.FindGameObjectWithTag("Player"); GameObject[] cloudList = GameObject.FindGameObjectsWithTag("Cloud"); GenerateMap generateMap = GameObject.Find("Generator").GetComponent <GenerateMap>(); ScoreManager scoreManager = GameObject.Find("ScoreManager").GetComponent <ScoreManager>(); BackgroundCreator backgroundCreator = GameObject.Find("BackgroundCreator").GetComponent <BackgroundCreator>(); Settings settings = GameObject.Find("Buttons").GetComponent <Settings>(); Destroy(playerLast); GameObject player = Instantiate(prefab, shop.SpawnPoint.position, Quaternion.identity); settings.GetComponent <Settings>().player = player.GetComponent <PersonController>(); generateMap.GetComponent <GenerateMap>().player = player.GetComponent <Transform>(); scoreManager.GetComponent <ScoreManager>().player = player.GetComponent <Transform>(); backgroundCreator.GetComponent <BackgroundCreator>().player = player.GetComponent <Transform>(); for (int i = 0; i < cloudList.Length; i++) { cloudList[i].GetComponent <Cloud>().player = player; } }