Search Unity

For what functions we use the word "On"?

Discussion in '2D' started by YanivAvrahami, Mar 22, 2017.

  1. YanivAvrahami

    YanivAvrahami

    Joined:
    Jun 26, 2016
    Posts:
    51
    Unity uses the word "On" a lot in its function like: OnTriggerEnter, OnCollisionEnter, OnDrawGUI, OnDrawScene, OnDrawInspector, and more.
    It's sounds good to add the word "On" in my own functions like: OnEndLevel, OnStartLevel, OnArrowFire, OnJump.

    Is it a good habit or bad habit to use it like that?
     
    Last edited: Mar 22, 2017
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,508
    It's a good habit and helps understand what functions do, just make sure you aren't overlapping unity functions and that you actually call the function. Unitys On functions are automatically called.
     
  3. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    Functions that begin with On are generally event-triggered function calls, used as a reaction or callback to an event that occurred.
     
    webox likes this.