public void Play() { string contents = File.ReadAllText(pathLevel); levelJson = JsonUtility.FromJson <LevelJsonScript>(contents); PlayerPrefs.SetString("LevelPath", pathLevel); if (levelJson.styleIndex == 0) { SceneManager.LoadScene(2); } else { SceneManager.LoadScene(3); } }
void ReadData(string path) { if (File.Exists(path)) { string contents = File.ReadAllText(path); levelJsonScript = JsonUtility.FromJson <LevelJsonScript>(contents); for (int i = 0; i < rigidObjects.childCount; i++) { Destroy(rigidObjects.GetChild(i).gameObject); } try { player.transform.position = levelJsonScript.positionPlayer; playerCamera.transform.eulerAngles = levelJsonScript.rotationPlayer; } catch {} for (int i = 0; i < levelJsonScript.indexPrefabs.ToArray().Length; i++) { GameObject instantiateObject = Instantiate(prefabs[levelJsonScript.indexPrefabs.ToArray()[i]], levelJsonScript.positionObjects.ToArray()[i], Quaternion.Euler(levelJsonScript.rotationObjects.ToArray()[i]), rigidObjects); instantiateObject.GetComponent <Rigidbody>().isKinematic = true; instantiateObject.name = prefabs[levelJsonScript.indexPrefabs.ToArray()[i]].name; if (instantiateObject.GetComponent <Food>() && levelJsonScript.temp.ToArray().Length > 0 && levelJsonScript.cooked.ToArray().Length > 0 && levelJsonScript.colors.ToArray().Length > 0) { instantiateObject.GetComponent <Food>().foodTemp = levelJsonScript.temp.ToArray()[i]; instantiateObject.GetComponent <Food>().cooked = levelJsonScript.cooked.ToArray()[i]; instantiateObject.GetComponent <MeshRenderer>().material.color = levelJsonScript.colors.ToArray()[i]; if (instantiateObject.GetComponent <Food>().foodTemp >= instantiateObject.GetComponent <Flamable>().tempUntilIgniteFire) { GameObject fire = Instantiate(otherPrefabs[0]); fire.GetComponent <FireAnimate>().fireBase = instantiateObject.GetComponent <Flamable>(); fire.GetComponent <FollowGameObject>().follow = instantiateObject; fire.GetComponent <FollowGameObject>().distance = Vector3.zero; } } if (levelJsonScript.blends.ToArray().Length != 0 && rigidObjects.GetChild(i).GetComponent <MeshRenderer>() && instantiateObject.GetComponent <MeshRenderer>().material.shader.name == "TextureChange") { instantiateObject.GetComponent <MeshRenderer>().material.SetFloat("_Blend", levelJsonScript.blends.ToArray()[i]); } } for (int i = 0; i < lightSwitches.Length; i++) { lightSwitches[i].switchBool = levelJsonScript.lightSwitches.ToArray()[i]; } cashRegister.money = levelJsonScript.money; tutorialScript.isSkipped = levelJsonScript.skippedTutorial; StartCoroutine(TimerFroze()); } }