Announcement

Collapse
No announcement yet.

Health Cases not enabling

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Health Cases not enabling

    In my Final Project, when I would take damage my cases would become false and my UI would disappear as it should however when I added my cowboy hat health power up, I would walk over it, it disappears but my health UI wouldn't appear again.

    Click image for larger version

Name:	Screen Shot 2020-05-01 at 5.02.20 PM.png
Views:	7
Size:	31.1 KB
ID:	344649Click image for larger version

Name:	Screen Shot 2020-05-01 at 4.51.24 PM.png
Views:	11
Size:	173.6 KB
ID:	344648Click image for larger version

Name:	Screen Shot 2020-05-01 at 4.51.59 PM.png
Views:	7
Size:	88.0 KB
ID:	344650

  • #2
    You likely don't have a Trigger on your character so you won't have an OnTriggerEnter method on a script attached to your character.

    It's unclear where these chunks of code are, but all of the stuff in your OnTriggerEnter method should actually be back on your HealthUI and in a different type of function. There you should probably have a public method called IncreaseHealth() or something like that, and then have most of what you currently have in OnTriggerEnter there.

    Then, on the powerup GameObject, you should have a Trigger, and a script that looks something like:
    Code:
    public class PowerUpScript:Monbehaviour
    {
         void OnTriggerEnter(collider other)
         {
              if(other.gameObject.tag == "Player)
              {
                   other.gameObject.GetComponent<HealthUI>().IncreaseHealth();
                   Destroy(gameObject);
              }
         }
    }
    Also, it's a lot easier if we actually work with script. Take a look at http://www.uiw3d.com/downloads/GameE...deWrapper.html

    Comment


    • #3
      Thank you and when I plugged in my code into a power-up script it would disappear and the same problem my health.indicator would disappear so this is my HealthUI.
      Code:
      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      using UnityEngine.UI;
      using UnityEngine.SceneManagement;
      
      public class HealthUI : MonoBehaviour
      {
          int health;
          public Image healthIndicator100;
          public Image healthIndicator75;
          public Image healthIndicator50;
          public Image healthIndicator25;
      
          public GameObject healthHat;
      
          public void Start()
          {
              health = 100;
          }
      
          public void DoDamage()
          {
              health = health - 25;
              switch (health)
              {
                  case 75:
                      healthIndicator100.enabled = false;
                      break;
                  case 50:
                      healthIndicator75.enabled = false;
                      break;
                  case 25:
                      healthIndicator50.enabled = false;
                      break;
                  case 0:
                      healthIndicator25.enabled = false;
                      break;
      
                  default:
                      break;
              }
      
              if (health <= 0)
              {
                  SceneManager.LoadScene("GameOver");
              }
          }
      
          public void IncreaseHealth()
          {
              if (health < 100)
              {
                  health = health + 25;
                  switch (health)
                  {
                      case 75:
                          healthIndicator100.enabled = true;
                          break;
                      case 50:
                          healthIndicator75.enabled = true;
                          break;
                      case 25:
                          healthIndicator50.enabled = true;
                          break;
                      default:
                          break;
                  }
      
              }
          }
      
      }

      Comment


      • #4
        This script looks pretty good. Can you post the script you have on the powerup?

        Comment


        • #5
          Here it is
          Code:
          using System.Collections;
          using System.Collections.Generic;
          using UnityEngine;
          
          public class PowerUpScript : MonoBehaviour
          {
              void OnTriggerEnter(Collider other)
              {
                  if (other.gameObject.tag == "Player")
                  {
                      other.gameObject.GetComponent<HealthUI>().IncreaseHealth();
                      Destroy(gameObject);
                  }
              }
          }

          Comment


          • #6
            That also looks pretty good; although it will destroy the health powerup even if you have 100 health. Not sure what's happening there. Come on over to Zoom and let's see if we can figure it out.

            Comment

            Working...
            X