public void NewGame(int planetsCount) { GenerateNewGameState(planetsCount); if (_gameSave.IsSaveExist()) { _gameSave.Clear(); } SceneManager.LoadScene(GAME_SCENE_INDEX, LoadSceneMode.Single); }
// Update is called once per frame void Update() { // autosave if it's time if (Time.time - last_autosave_time > AUTOSAVE_PERIOD_SECONDS) { Save(); last_autosave_time = Time.time; Debug.Log("Autosaving"); } // Set walking / sitting animiation float velocity = agent.velocity.magnitude; if (velocity < 0.2) { animator.SetBool("moving", false); forced_walk = false; if (!forced_sit && animator.GetCurrentAnimatorStateInfo(0).IsName("Walk")) { animator.SetFloat("speed", 1.0F); animator.Play("Walk", -1, 0.9F); forced_sit = true; } } else { forced_sit = false; animator.SetBool("moving", true); if (!forced_walk && animator.GetCurrentAnimatorStateInfo(0).IsName("Idle")) { animator.Play("Idle", -1, 0.8F); forced_walk = true; } animator.SetFloat("speed", velocity); } // Update achievements achievements.GetNewUnlocks(); // TODO: autosave // Save game when S is pressed if (Input.GetKeyDown(KeyCode.S)) { Save(); } // Load game when L is pressed if (Input.GetKeyDown(KeyCode.L)) { Load(); } // If R is pressed, reset if (Input.GetKeyDown(KeyCode.R)) { CreateNew(); GameSave.Clear(); } // Calcuate time delta since last update, in seconds, fps-independent calculations float dt = Time.time - last_update_time; achievements.time_played += dt; last_update_time = Time.time; // Update cat stats with current state personality.UpdateStats(ref stats, activity, dt); // Update UI stats.UpdateUI(); // Run behavior tree. If a tree is "paused", it will not run. StartCoroutine(runTree(Time.time)); // If cat is currently interacting with user, the camera should follow the cat if (userInteractionBehaviorTree.paused == false) { Camera.main.transform.LookAt(gameObject.transform); // Main camera look at cat } // Log current state //Debug.Log(activity); //Debug.Log(stats); //Debug.Log(achievements); }