void OnTriggerEnter2D(Collider2D collision) { Energy e = collision.gameObject.GetComponent <Energy>(); if (e != null) { e.Collect(); UpdateEnergy(energy + e.amount); } }