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");
}
}
}
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.