public void AddPoints(int points) { score += points; // add to health every 50 pts if (score % 50 == 0) { //hObj.health += 1; hObj.AddHealth(); Debug.Log("HEALTH: " + hObj.health); } }
// Player triggers with colliders void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.tag == "Coins") { //Debug.Log("got coin"); // Add points to player score sObj.AddPoints(10); coinAudio.Play(); col.gameObject.SetActive(false); } // When player gets hurt else if (col.gameObject.tag == "Enemy") { // Health decrease by 1 hObj.TakeDamage(1); Debug.Log("HEALTH: " + hObj.health); hObj.tookDamage = true; ///// // Change player's color gotHurt = true; //Debug.Log("got spike hurt"); } // When player gets health pack else if (col.gameObject.tag == "Health") { // Health decrease by 1 hObj.AddHealth(); Debug.Log("HEALTH: " + hObj.health); // make health pack inactive col.gameObject.SetActive(false); gotHealth = true; } // When player dies else if (col.gameObject.tag == "DeathZone") { // Respawn player to beg of level // continue timer when player dies PlayerPrefs.SetFloat("TimeRem", tObj.timeRemaining); PlayerPrefs.SetFloat("TimeInc", tObj.timeInc); deathAudio.Play(); isDead = true; } // When player reaches end of level else if (col.gameObject.tag == "Finish") { PlayerPrefs.SetFloat("TimeRem", tObj.timeRemaining); PlayerPrefs.SetFloat("TimeInc", tObj.timeInc); PlayerPrefs.SetInt("Player Score", sObj.score); PlayerPrefs.SetInt("Player Health", hObj.health); PlayerPrefs.SetInt("Player Deaths", deathCounter); /////////////////////// PlayerPrefs.SetInt("Extra Hearts", hObj.currentExtraHearts); PlayerPrefs.SetInt("Took Damage", (hObj.tookDamage ? 1 : 0)); if (SceneManager.GetActiveScene().name == "WinScreen") { PlayerPrefs.SetFloat("TimeRem", 900); PlayerPrefs.SetFloat("TimeInc", 0); } isNewGame = false; advanceLevel = true; } }