12
Urkaz
8y

Found this pearl on the code of the game I made with some friends on a game jam the last week
Beautiful

Comments
  • 1
    Hey after 18 hrs no stop, your brain starts processing things slower. At that point if it runs it's good lol. Gamejams are fun!
    I bet that piece of code is inside a OnTriggerEnter (Collider other) Unity ftw!
  • 1
    Well, because it is a function that takes a string as a parameter, which then takes it to the key code/axis, and then takes it to the actual keyboard state.

    I believe they were right to do so. Functions can be expensive.
  • 0
    I'm with @RexOmni here, that's not redundant. This reminds me of the new guy at my office that makes outbursts insulting others' code all the time. He still hasn't learned that for 90% of his insulting outbursts, there's something in the logic that has to be explained... Don't be that guy.
  • 0
    Doesn't look to me like he is insulting anyone's code. More like laughing at his own. We don't have much context but since one of the team members posted it as redundant, I think it's safe to assume that the activate flag was unnecessary.
  • 2
    @neotelos @RexOmni As @aaeim said, the resundant part is the activated flag (it isn't needed at all). This is a onTriggerStay Unity function that reads the "E" key input (0 not pressed, 1 pressed). The point here is: if the key is pressed the flag is set to true, then it is checked and set to false. That can be done the same way just moving the contents of the second if to the first one without changing the flag value xD
  • 2
    @Urkaz Forget to mention it, but that flag is used only on the code of the photo xD
Add Comment