- Home /
Question by
nothjarnan · Oct 11, 2013 at 04:53 PM ·
textchangeflashlight3dtext
Unity3d Battery Life Change 3D text Java script
I need some help with changing a 3D text to the amount of battery life left on the flashlight, for my upcoming game. heres the code for battery life / flashlight
pragma strict
public var maxBatteryLife: float = 100.0f;
public var batteryLifeLostPerSecond: float = 3.0f;
public var linkedLight: Light;
public var currentBatteryLife: float;
function Start() {
currentBatteryLife = maxBatteryLife;
}
function Update() {
if (Input.GetKeyDown("f")) {
linkedLight.enabled = !linkedLight.enabled; // Toggles the light
}
if (linkedLight.enabled) {
currentBatteryLife -= batteryLifeLostPerSecond * Time.deltaTime; // Reduces the battery correctly over time
}
if (currentBatteryLife <= 0) {
linkedLight.enabled = false; // Keeps the light off when there is no power.
}
}
any ideas on where to place the code for it? and how to make that code?
Comment