- Home /
This question was
closed Apr 29, 2018 at 02:41 PM by
Baniucha for the following reason:
I found a solution
Methods and loops problem
Hi I am creating a basic 2d platformer and I have a problem. So the main idea is when player reaches durability of pickaxe to 0, then the text shows up and it says "repair your pickaxe by clicking R". However it does not work for me. I think it may be because of loop that I created but also I think I may set wrong methods here is the script:
private void Update() { if (Input.GetKeyDown("f")) { curDurability -= 2;
if (curDurability <= 0)
{
curDurability = 0;
dmg.dmg = 0;
repairText.enabled = true;
Repair(curDurability);
}
else
{
repairText.enabled = false;
dmg.dmg = 1;
}
}
durabilityText.text = ("Durabiltiy: " + curDurability);
}
public void Repair(int curDur)
{
if (Input.GetKeyDown("r"))
{
curDur = 20;
curDurability = curDur;
}
return;
}
Comment
try
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.R))
and make sure repair is called in update.