- Home /
Question by
OctoSloths · Nov 04, 2014 at 03:34 PM ·
javascriptcollisiondamagehealth
Player take damage on collision with AI
I am new to coding and I am trying to make my player take damage when an AI touches it, this is my code so far:
var maxHealth = 100;
public static var currentHealth = 100;
var PlayerHealthDisplay : GUIText;
function Start() {
DisplayAmount();
}
function DisplayAmount () {
PlayerHealthDisplay.text = ""+ currentHealth;
}
function OOnTriggerEnter(collider:Collider) {
if (collider.tag == "beep"){
currentHealth += -10;
PlayerHealthDisplay.text = ""+ currentHealth;
}
}
The player does not take any damage though, how should I change it?
Comment
with ExtremePowers
function OOnTriggerEnter(collider:Collider) {
to
function OnTriggerEnter(collider:Collider) {
?
and you could change this
currentHealth += -10;
to this
currentHealth -= 10;
Best Answer
Answer by Wisearn · Nov 04, 2014 at 03:45 PM
Typo here:
function OOnTriggerEnter(collider:Collider) {
one too many O in OnTriggerEnter