using System.Collections; using System.Collections.Generic; using UnityEngine; public…
- User
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class EnemyHealth : MonoBehaviour { public int maxHealth = 1; private int currentHealth;
codeprivate void Start() { currentHealth = maxHealth; } public void TakeDamage(int damageAmount) { currentHealth -= damageAmount; if (currentHealth <= 0) { Die(); } } private void Die() { // Destroy the enemy object when health reaches 0 Destroy(gameObject); }} make it so if the enemy dies the score goes up +50 points. Here is the ScoreCounter script for reference: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; //This line enables use of uGUI classes like Text.
public class ScoreCounter : MonoBehaviour { [Header("Dynamic")] public int score = 0;
codeprivate Text uiText; // Start is called before the first frame update void Start() { uiText = GetComponent<Text>(); } // Update is called once per frame void Update() { uiText.text = score.ToString("Score:#,0"); //This 0 is a zero! }}
- Assistant
To make the score go up by 50 points when the enemy dies, you can modify the EnemyHealth script like this:
csharpusing System.Collections; using System.Collections.Generic; using UnityEngine; public class EnemyHealth : MonoBehaviour { public int maxHealth = 1; private int currentHealth; private ScoreCounter scoreCounter; // Reference to the ScoreCounter script private void Start() { currentHealth = maxHealth; scoreCounter = FindObjectOfType<ScoreCounter>(); // Find the ScoreCounter script in the scene } public void TakeDamage(int damageAmount) { currentHealth -= damageAmount; if (currentHealth <= 0) { Die(); } } private void Die() { // Add 50 points to the score when the enemy dies scoreCounter.score += 50; // Destroy the enemy object when health reaches 0 Destroy(gameObject); } } - User
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;
public class BossHealth : MonoBehaviour { public int maxHealth = 5; private int currentHealth;
codeprivate void Start() { currentHealth = maxHealth; } public void TakeDamage(int damageAmount) { currentHealth -= damageAmount; if (currentHealth <= 0) { Die(); } } private void Die() { // Destroy the boss object when health reaches 0 Destroy(gameObject); // Check if the current scene is "Level1" and change to "Level2" if true if (SceneManager.GetActiveScene().name.Equals("Level1")) { SceneManager.LoadScene("Level2"); } }} now make it so that when the boss dies there is +300 points
- Assistant
To add 300 points to the score when the boss dies, you can modify the BossHealth script like this:
csharp