- Home /
Unknown identifier, OnCollisionEnter Error
Hi, in my script health.js I have a static variable playerhealth with an GUI health bar. Anyway when i try to deduct health when the player hits the enemy i get the error BCE0005: Unknown identifier: 'health'. I've tried everything and have had no luck. Thanks in advance for your help!
function OnCollisionEnter(collision : Collision)
{
if (collision.gameObject.tag == "Enemy")
{
health.playerhealth -= 10;
}
}
Answer by code-blep · Nov 27, 2012 at 09:26 PM
Hi HunterKrech,
health.playerhealth -= 10; looks like you are trying to change the integer 'playerhealth' in a script called 'health'. I would say that your reference to the script 'health' is incorrect.
You would refer to the script doing something like this:
var healthScript : health;
healthScript = GameObject.Find("Name of GameObject that the script is attached to").GetComponent(health);
Hope this helps :)
Paul
Your answer
Follow this Question
Related Questions
Accessing another var on another script 1 Answer
How would I be able to subtract from a variable when it hits something? (OnCollisionEnter) 1 Answer
Trivial question for Javascript/Unityscript experts: static variables? 4 Answers
Changing The Value Of A Variable From Another Script (JavaScript) 1 Answer
Global variables - static keyword ? UnityScript? javascript? 1 Answer