The local function 'OnCollisionEnter' is declared but never used

Im trying to code a jump feature for my game and I get “The local function ‘OnCollisionEnter’ is declared but never used” when I save my script. Code:
void OnCollisionEnter(Collision collision) {

if(collision.gameObject.tag == “platform”) {

jump = true;

}

}

Your problem is that this little code snippet is living inside another one of your functions. For example, it probably looks something like this right?

void Update() { // This is the start of the Update function
  //some code

  void OnCollisionEnter(Collision collision) {
    // code
  }
} // <<< end of Update function is here, meaning your OnCollisionEnter is inside Update

What you want is for them to be separate functions. Like this:

void Update() [
  // some code
}

void OnCollisionEnter(Collision collision) {
  // code
}

When the compiler talks about a “local function” it’s talking about how you have one function inside another.

3 Likes

Thx That makes more sense