- Home /
Increase energy bar by collecting item, partially working
Hi Unity Community,
When my character jumps, I got the energy bar to go down, but I am trying to increase energy when the player collides with an item. The way I am trying to do this is by playing with the localScale of the EnergyBar. I am using a boolean called "addEnergy" to check if I should increase the scale of the energyBar. So far every time the Player collides with "item" the addEnergy becomes "true" for a moment, but doesn't add to the energy bar. It only adds when I collect all the items. Wondering what could be causing this issue.
Here is the code that checks collision:
var addEnergy : boolean = false;
function Update () {
Debug.Log(addEnergy);
}
function OnCollisionEnter2D(other : Collision2D){
if(other.gameObject.tag == "Player"){
addEnergy = true;
transform.localPosition = Vector3(0, 0, -100);
}
}
function OnCollisionExit2D(other : Collision2D){
addEnergy = false;
}
Just realized that I don't have to collect all the items for it to work, but it only work with one GameObject. The other GameObjects are copies of the original one with the same script.
Your answer
Follow this Question
Related Questions
OnCollisionStay for seconds then destroy 0 Answers
Destroy a GameObject 2 Answers
Overlap Detection HELP!! 0 Answers
Change scene with trigger collision not working. 1 Answer
Collsion without ririgibody 1 Answer