Set Bool to false after seconds?

Hi!
I’m quite new to Unity, (well in my books, a few months + no training = new lol) therefore I’m not the best at coding, and I was wondering if I could get a few pointers. I have an animation for my player to raise a gun on cue (I can’t get it back down, I have a bool parameter so that when I hit space the bool = true, and I couldn’t get it back down again it kept giving me compiling errors) Also I’ve been trying to get the actual gunshot animation to work (I have it with another bool so when you hit “z”, Bang = true but the issue is that it stays true (leaving you frozen with no animation) and I’m thinking I could use a timer so it becomes false before the animation is over so it just goes back to the idle animation, but I couldn’t get that working either. I eventually got bored and focused more on art (I have glow effects and lens flares + my art it looks AWESOME) but you cant do much other than take out your gun and shoot once (But then you’re stuck, frozen). I also had some dialogue working, but I must’ve messed up colliders and now the whole thing is just a mess with sitting code that doesn’t do anything lol. No compiling errors (That make it unplayable anyway) and looks gorgeous. Anyway if someone could help me out in any small way I would be extremely grateful as this is my ultimate dream (not to be cheesy) but I’ve always wanted to do this and this is my first game. :slight_smile:

bool bang;
public float m_TimeUntilBang;

void Start()
{ 
Invoke("Onbang", m_TimeUntilBang);
}

void OnBang()
{
   bang = !bang; 
//Or it could be 
 bang = false;
}
Void YOURMETHOD()
{
Invoke("Onbang", m_TimeUntilBang);
 }
}

 


I rather use invoke its easier to set up and to me a more convenient way to use a timer.

bool bang;
public float m_TimeUntilBang;

void OnBang()
{
bang = !bang;
//Or it could be
bang = false;
}
Void YOURMETHOD()
{
Invoke(“Onbang”, m_TimeUntilBang);
}
}

you could also call your method in the start function. so

void Start()
{
YOURMETHOD();
}

I rather use invoke its easier to set up and to me a more convenient way to use a timer.

You might want to post some of your animation code and your Animator controller setup. This might be either a logic issue or a transition problem.

@Nighfox Heya! Thanks for the reply, here is my animator and a few lines of code, hope this makes sense lol. Like I said I’m pretty new to this.