Slider Fill Area deactivate after jump
I have a slider that shows the force of my characters jump. The longer you hold the mouse the higher he jumps. When he jumps and is in air I have the force disabled so the character won't dubble jump. But the slider Fill Area still visually increases when holding the mouse down. How can I disable this?
powerBar.interactable = false; doesn't seem to work
powerBar.enable doesn't seem to work either.
Answer by Jojoba007 · Feb 17, 2017 at 12:44 PM
@ArmanDoesStuff What .SetActive does is hide the whole Slider. I would like to only have the fill area of the slider not working anymore after jumping, so you won't be able to increase the fill while in mid air.
Oh, right. It's quite hard to visualise what you mean without seeing the code but I think I get what you mean.
So you don't want to disable the slider fill, you just want to fix its value after the jump? In that case, couldn't you just disable anything that is affecting the slider value?
Again, I havn't seen your code but I imagine even something super simple like creating a "bool isJumping" that sets true after the jump, and then only have the mouse increase the jump power/slider value "if (isJumping == false)"
thanks for the respons.
If I jump and I'm in mid air the powerBar won't effect the characters jump force anymore, but I can still visually see the slider go up again while clicking again after jump in mid air. I'm trying to disable the fill area responding to the mouseclick while in mid air.
I have the following code installed for it, but it doesn't seem to affect anything on the fill area of the slider. Hope I'm explaining myself correctly now ;-) I'ts hard to explain without showing the project. :-0
void DisablePowerBarFillIn$$anonymous$$idAir ()
{
if (isGrounded == false) {
powerBar.enabled = false;
}
}
I also tried powerBar.interactable = false; but doesn't work either.
Have you tried putting the "if (isGrounded == true)" on the mouse click ins$$anonymous$$d?
Again, I'm just assu$$anonymous$$g what your code is but maybe something like:
void Update()
{
if (Input.GetAxis("jump") && isGrounded == true)
{
//increase jump slider
}
}
Answer by ArmanDoesStuff · Feb 16, 2017 at 10:50 AM
powerBar.SetActive(false);
@ArmanDoesStuff I'm getting the following error: 'UnityEngine.UI.Slider' does not contain a definition for 'SetActive'.
I did get the component: powerBar = GameObject.Find ("Power Bar").GetComponent();
??
SetActive is under GameObject. So if you want to deactivate something via script you have to deactivate what it's attached to.
For example:
Slider powerBar = GameObject.Find("Power Bar");
powerBar.GameObject.SetActive(false);
Your answer
Follow this Question
Related Questions
Buttons: How to enable, disable and enable same button again? 1 Answer
Slider to disable Augmented Reality,Slider Script, Disable script camera 0 Answers
Selectively enable and disable Gamepads?,D 0 Answers
Slider que desactive script en la camara 0 Answers
Im trying to create a crash bandicoot spin but how do i make it disabled after a second? 2 Answers