Need Help quick

Hey im trying to convert the C# Health script from Brug zerg arcade to a Javascript but a get an error

C# script

using UnityEngine;
using System.Collections;

public class PlayerHealth : MonoBehaviour {
    public int maxHealth = 100;
    public int curHealth = 100;

    public float HealthBarLength;

	// Use this for initialization
	void Start () {
        HealthBarLength = Screen.width / 2;
	}
	
	// Update is called once per frame
	void Update () {
        AddjustCurrentHealth(0);
	}

    void OnGUI(){
        GUI.Box(new Rect(10, 10, HealthBarLength, 20), curHealth + "/" + maxHealth);
    }

    public void AddjustCurrentHealth(int adj){
        curHealth += adj;

        if(curHealth < 0)
            curHealth = 0;

        if(curHealth > maxHealth)
            curHealth = maxHealth;

        if(maxHealth < 1)
            maxHealth = 1;

        HealthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);
    }



}

My JS Script

var maxHealth = 100;
var curHealth = 100;
var healthBarLength ;
var adj ;

function start ()
{
	healthBarLength = Screen.width / 2;
}

function Update ()
{
	AddjustCurrentHealth(0);
}

function OnGUI()
{
	GUI.Box (new Rect(10, 10, healthBarLength, 20), curHealth + "/" + maxHealth);
}

function AddjustCurrentHealth ()
{
	curHealth += adj;
	
	if(curHealth < 0)
	curHealth = 0;
	
	if(curHealth > maxHealth)
	curHealth = maxHealth;
	
	if(maxHealth < 1)
	maxHealth = 1;
	
	healthBarLength = (Screen.width / 2) * (curHealth / maxHealth);
}

The error i get

At line 13

thx :slight_smile:

You’re trying to pass an int into the AddjustCurrentHealth method, but the method is not defined to accept any arguments. Change the method to accept an int argument.

hehe well i have been up for some time now (its a school project :P) so if you could cut it out for me :slight_smile:

Here is:

var maxHealth = 100;
var curHealth = 100;
var healthBarLength ;

function start ()
{
	healthBarLength = Screen.width / 2;
}

function Update ()
{
	AddjustCurrentHealth(0);
}

function OnGUI()
{
	GUI.Box (new Rect(10, 10, healthBarLength, 20), curHealth + "/" + maxHealth);
}

function AddjustCurrentHealth (adj)
{
	curHealth += adj;
	
	if(curHealth < 0)
	curHealth = 0;
	
	if(curHealth > maxHealth)
	curHealth = maxHealth;
	
	if(maxHealth < 1)
	maxHealth = 1;
	
	healthBarLength = (Screen.width / 2) * (curHealth / maxHealth);
}

THX alot to the both of you :slight_smile:

ok i get a bug with this when i try to adjust the healthbar through the curHealth instead of adjusting the healthbar it just disappears. :frowning: i can see that in the C# script i have a (float) in front of maxhealth at line 36 in the C# but not in the JS can that be it and how do i fix it :slight_smile:

anybody ?? :slight_smile: i have tried and tried but i just cant figure out how to fix it :frowning:

sorry for bump :slight_smile: