Can't change int Value (C#)

This may be me being stupid, but I’m trying to make the flashlight battery increase to make a hundred (when you pick up a batter pack) but it stays on the battery it was already on

(flBattery is the battery count)

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Battery : MonoBehaviour {

	public float flBattery = 100;
	public Text batteryTxt;
	public Light flashlight;
	public Image bHigh;
	public Image bMed;
	public Image bLow;
	public Image bNone;
	public float batteryDrainSpeed = 0.15f;
	public GameObject batteryPickup;
	public Text pickUpText;
	public Light lightSrc;
	private int flashInt;

	// Use this for initialization
	void Start () {
		pickUpText.enabled = false; 
		StartCoroutine ("BatteryLoss");
		bMed.GetComponent<Image> ().enabled = false;
		bLow.GetComponent<Image> ().enabled = false;
		bNone.GetComponent<Image> ().enabled = false;

	IEnumerator BatteryLoss() {
		while (flBattery > 0) {
			yield return new WaitForSeconds (batteryDrainSpeed);
			batteryTxt.text = (flBattery + "%");
			Debug.Log (flBattery);

	void OnTriggerEnter (Collider other) {
		flashlight.intensity = 3.0f;
		flBattery = 100;
		pickUpText.GetComponent<Text> ().enabled = true;
		StartCoroutine (pickUpFunc());

	IEnumerator pickUpFunc() {
		yield return new WaitForSeconds (2);
		GameObject.Destroy (batteryPickup);
		pickUpText.GetComponent<Text> ().enabled = false;

There could be many reasons for this … like

  1. One of your gameobjects, either your batter pack or the object that is trying to pick up this pack, should have rigidbody on it
  2. the collider of the gameobject this script is attached on is not a trigger
  3. script is on a wrong gameobject
  4. if flBattery is a floating point number then where is the f like 100f or 100.0f

Plus, if your OnTriggerEnter function is not in need of the collider info then why are you giving it as a parameter, you can remove it and save some computation

This isn’t just a matter of the script being a MonoBehaviour is it?

When you’ve got it on a GameObject in the scene and have typed in some different value in the inspector yourself (or have one from a previous version of the script), that value will overwrite the default value you set in the script.

Could be that, I remember it confused me a lot when I first started out with Unity.