Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question OnCollisionEnter Not Working

Discussion in 'Scripting' started by Mibird_9989, Apr 2, 2024.

  1. Mibird_9989

    Mibird_9989

    Joined:
    Jan 6, 2024
    Posts:
    2
    Currently OnCollisionEnter says its unused (IDE0051), even though im following strictly on the Junior Programmer Mission, and im not sure why. The Box Collider is on if that's useful. here's the entire script.


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerController : MonoBehaviour
    6. {
    7.     private Rigidbody playerRb;
    8.     public float jumpForce;
    9.     public float gravityMultiplier;
    10.     public bool isOnGround = true;
    11.     // Start is called before the first frame update
    12.     void Start()
    13.     {
    14.         playerRb = GetComponent<Rigidbody>();
    15.         Physics.gravity *= gravityMultiplier;
    16.     }
    17.  
    18.     // Update is called once per frame
    19.     void Update()
    20.     {
    21.  
    22.         if(Input.GetKeyDown(KeyCode.Space)&& isOnGround == true)
    23.         {
    24.             playerRb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
    25.             isOnGround = false;
    26.         }
    27.     }
    28.     private void OnCollisonEnter(Collision collision)
    29.     {
    30.         isOnGround  = true;
    31.     }
    32. }
    33.  
     
  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,448
    spiney199 and Kurt-Dekker like this.
  3. Mibird_9989

    Mibird_9989

    Joined:
    Jan 6, 2024
    Posts:
    2
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,005
    For all Unity's magic functions like this, I suggest either:

    1. make sure your IDE is properly configured (see below) so that it suggests the spelling properly

    2. copy/paste it by hand from the documentation every single time.

    Any other way is only going to waste way more time when your stuff misbehaves.

    AND... when you get a warning, take it seriously. Prove to yourself that it's not an issue rather than assuming it's a false alarm.

    As for setting up your IDE:

    This may help you with intellisense and possibly other Visual Studio integration problems:

    Sometimes the fix is as simple as doing Assets -> Open C# Project from Unity. Other times it requires more.

    Other times it requires you also nuke the userprefs and .vsconfig and other crufty low-value high-hassle files that Visual Studio tends to slowly damage over time, then try the above trick.

    Barring all that, move on to other ideas:

    https://forum.unity.com/threads/intellisense-not-working-with-visual-studio-fix.836599/

    Also, try update the package inside of Unity: Window -> Package Manager -> Search for Visual Studio Editor -> Press the Update button

    Depending on flavor and version of Visual Studio, it may also have an installation step that you perform within the actual Visual Studio. This step seems finicky at best and may require multiple openings of VS before it comes up.

    Update: The VSCode extension has been deprecated and abandoned:

    https://forum.unity.com/threads/update-on-the-visual-studio-code-package.1302621/

    Update: the VSCode integration is back... maybe!?

    https://forum.unity.com/threads/microsoft-previews-unity-extension-for-visual-studio-code.1468913/

    There may be a community fork available that is receiving updates.

    https://github.com/Chizaruu/com.tsk.ide.vscode

    Also, this: https://forum.unity.com/threads/no-suggestions-in-vscode.955197/#post-6227874

    Recently (July 2023) I worked on a Windows11 system that required a Microsoft component to be installed from within Visual Studio before it would work properly with all the OTHER software installed under Unity. I have no documentation on that process as I have only seen it once and it surprised me as well.