So right now I have the player swimming around and I’d like that when he collides with the surface his “air” refills. It seems that when he collides with the “surface” he looses it all and I beleive it might be from me trying to find the difference between the amount he has, and the amount he needs to fill up. Thanks!
using UnityEngine;
using System.Collections;
public class Meter : MonoBehaviour {
public float air = 10;
public float maxAir = 10;
public float airBurnRate = 1f;
private Player player;
// Update is called once per frame
void Update () {
if (air > 0) {
air -= Time.deltaTime * airBurnRate;
}
}
void OnCollisionEnter2D(Collision2D coll) {
if (coll.gameObject.tag == "Surface") {
Debug.Log ("AIR!!!");
var addair = air - 10; // Find the difference
air = air + addair; // Add the difference to fill up
}
}
}