i have made a melee script but it is not doing anything at all here it is:
var InCombat : boolean = false;
static var EnemyHealth;
static var MeleeLevel;
var SwordBonus = 20;
function Start(){
InCombat = false;
if(Input.GetKeyUp(KeyCode.F)){
Attack();
}
}
function Attack(){
InCombat = true;
if(Input.GetKeyUp(KeyCode.F)){
EnemyHealth -= SwordBonus * MeleeLevel / 4;
}
}
i want it to so if when it starts you are not in combat so you can not attack right away but if you press f then it turns combat on and you can attack right away but it does not do anything to the enemy i have enemy health script but it does not take damage from my script every time i press f the boolean doesn’t even turn on or the enemy doesn’t take damage please help.
Because you checked for F pressure in the Start() function. As a consequence, that control will be executed just a single time, as the game starts (and you won’t be so quick to press it in time, without taking into account that it will be unuseful). In other words, you can press F, but that pressure won’t be checked. You have to use Update().
Something like:
function Start(){
InCombat = false;
}
function Update(){
if(Input.GetKeyUp(KeyCode.F) && InCombat == false)
InCombat = true;
else if (Input.GetKeyUp(KeyCode.F))
Attack();
}
function Attack(){
EnemyHealth -= (SwordBonus * MeleeLevel / 4);
}
I don’t know if my script does exactly what you want (even because I don’t see the reason for a multiple control on F pressure), but it should address you to the right approach: remember that Update’s body is executed every frame, while Start’s body is executed just one time, at the beginning.