- Home /
Recharging battery script, help
this is a part of my script on my flashlight (spot light):
static function AlterEnergy (amount : int) {
energy = Mathf.Clamp(energy+amount, 0, 100);
}
I've also an inventory system, how can i recharge my flashlight whit a script?
I've tryed whit:
function UseEffect ()
{
Debug.LogWarning("Point light.AlterEnergy(batteryPower)");
var batteryPower : int = 100;
}
But it doesn't work
Answer by ChrisSch · Aug 25, 2013 at 06:40 PM
Not quite sure what you mean but, if the UseEffect function is what you want to recharge your battery variable then if you defined the variable outside any function all you have to do is instead of:
function UseEffect ()
{
Debug.LogWarning("Point light.AlterEnergy(batteryPower)");
var batteryPower : int = 100;
}
Write:
function UseEffect ()
{
Debug.LogWarning("Point light.AlterEnergy(batteryPower)");
batteryPower = 100;
}
Writing var in front of the variable you want to alter its value, doesn't alter it, instead it declares it again, and I don't think it would allow you to declare it if you already declared it.
Your answer
Follow this Question
Related Questions
Flashlight Battery Error No definition 1 Answer
Flashlight battery script 3 Answers
Rechargeble flashlight with battery pick up 1 Answer
Flashlight pickup, battery etc 3 Answers
Pressing "Fire2" Spawns and removes object on click 0 Answers