Issues with trigger

Forum Archive Issues with trigger

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #7755
    micj27
    Participant

      For some reason I am heaving issues with collision and trigger detection. From what i can tell I followed the code properly but my text is not updating. I have the cube checked as is trigger and the script is on the cube. the sphere is labeled player. I put a debug.Log in the if statement but it does not output so I assume it is not seeing the collision or the tag. Code Below:

      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      using UnityEngine.UI;
      
      
      public class pickupHealth : MonoBehaviour {
      
      
          public Text healthText;
          public int pickupAmount = 10;
          public int currentHealth = 50;
      
      
          // Use this for initialization
          void Start () {
      
      
              healthText = GameObject.Find("Text").GetComponent<Text> ();
          }
          
          // Update is called once per frame
          void Update () {
              healthText.text = "Health " + currentHealth;
          }
      
      
          void onTriggerEnter(Collider col){
              if(col.gameObject.tag == "Player"){
      
      
                  currentHealth += pickupAmount;
                  Debug.Log("player detected: add health");
              }
      
      
          }
      }
      
      #27609
      Jonathan Gonzalez
      Participant

        It’s OnTriggerEnter. It’s case sensitive, so you have onTriggerEnter which Unity thinks is a custom method you created and not the built in OnTriggerEnter it’s supposed to use. Case sensitivity is something to really pay close attention as small things like this can completely throw you off. 

        #27610
        micj27
        Participant

          Oh I see. thank you. I lose track of which functions are upper and lower

        Viewing 3 posts - 1 through 3 (of 3 total)
        • The topic ‘Issues with trigger’ is closed to new replies.