hi, i was trying to convert these scripts c # to javascript, but they are not working correctly.
playerHealth javascript:
public var maxHealth : int = 100;
public var curHealth : int = 100;
public var healthBarLenght : float;
// Use this for initialization
function Start () {
healthBarLenght = Screen.width / 2;
}
// Update is called once per frame
function Update () {
addjustCurrentHealth(0);
}
function OnGUI () {
GUI.Button(new Rect(10, 40, healthBarLenght, 20), curHealth + "/" + maxHealth);
}
function addjustCurrentHealth(adj : int) {
curHealth += adj;
if(curHealth < 0)
curHealth = 0;
if(curHealth > maxHealth)
curHealth = maxHealth;
if(maxHealth < 1)
maxHealth = 1;
healthBarLenght = Screen.width / 2 * curHealth/(maxHealth);
}
playerAttack javascript:
var target : GameObject;
var attackTimer : float;
var coolDown : float;
function Start () {
attackTimer = 0;
coolDown = 0.45f;
}
function Update() {
if(attackTimer > 0)
attackTimer -= Time.deltaTime;
if(attackTimer < 0)
attackTimer = 0;
if(Input.GetButton("Fire1")) {
if(attackTimer == 0)
attackTimer = coolDown;
}
}
private function attack () {
var distance : float = Vector3.Distance(target.transform.position, transform.position);
var dir : Vector3 = (target.transform.position - transform.position).normalized;
var direction : float = Vector3.Dot(dir, transform.forward);
if(distance < 0.8) {
if(direction > 0) {
var eh : enemyVida = (enemyVida).target.GetComponent("enemyVida");
eh.addjustCurrentHealth(-10);
}
}
}
someone could help me.