- Home /
Question by
goten000023 · Jul 29, 2014 at 01:19 AM ·
javascriptfpsnewhealth
health script will not work
well i have been making this health script and i get this error, i am fairly new to unity javascript
BCE0044: expecting (, found 'Die'.
and here is the health script,
var curHealth : int = 100;
var maxHealth : int = 100;
var Enemy : gameobject;
function Start () {
}
function Update () {
if(curHealth < 0 ) {
curHealth = 0;
}
if(curHealth > 100) {
curHealth = 100;
}
if(col.gameObject.name == "Zombie"){
curHealth -= 10;
}
{
if (curHealth <= 0)
Die();
}
function Die(){
Destroy(Enemy);
}
}
Comment
i bet your problem is on line 18, you have to use a function for that collision
Best Answer
Answer by HolBol · Jul 29, 2014 at 01:37 AM
var curHealth : int = 100;
var maxHealth : int = 100;
var Enemy : gameobject;
function Start () {
}
function Update () {
if(curHealth < 0 ) {
curHealth = 0;
}
if(curHealth > 100) {
curHealth = 100;
}
if(col.gameObject.name == "Zombie"){
curHealth -= 10;
}
{
if (curHealth <= 0)
Die();
}
}
function Die(){
Destroy(Enemy);
}
Your function Die() was in another function. It has to be separate.
well now it says,
BCE0018: The name 'gameobject' does not denote a valid type ('not found'). Did you mean 'UnityEditor.GameObjectUtility'?
and thanks in advance.
Answer by Leooc13 · Jul 29, 2014 at 05:44 AM
var curHealth : int = 100;
var maxHealth : int = 100;
var Enemy : GameObject;
function Start () {
}
function Update () {
if(curHealth < 0 ) {
curHealth = 0;
}
if(curHealth > 100) {
curHealth = 100;
}
if(col.gameObject.name == "Zombie"){
curHealth -= 10;
}
{
if (curHealth <= 0)
Die();
}
}
function Die(){
Destroy(Enemy);
}
GameObject, not gameobject.
got it to work fine,
the only thing is i will have to probably put the collision on to a bullet and call it that way.
and thanks so much!
Your answer
![](https://koobas.hobune.stream/wayback/20220613155237im_/https://answers.unity.com/themes/thub/images/avi.jpg)