Search code examples
c#unity-game-enginevisual-studio-2019

Cannot detect class "MonoBehavior". Hence "Rigidbody" does not detect it. Why is that?


I'm writing the code but the editor doesn't detect it. I looked in many places but could not solve the problem."Rigidbody" does not turn blue. Thank you in advance for your help. enter image description here

using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class KarakterKontrol : MonoBehaviour
    {
        // Start is called before the first frame update
        void Start()
        {
            Rigidbody fizik = GetComponent<Rigidbody>();
    
        }
    
        // Update is called once per frame
        void Update()
        {
            
        }
    }

Solution

  • I took a quick look at what "Diger dosyalar" meant.. which roughly translates to "Other Files", or in the English version of Visual Studio, Miscellaneous Files.

    What that means is that your Visual Studio is not properly synced with Unity. You're seeing just a plain old C# file by itself, not a file that is associated with a Project.

    The steps to rectify are usually:

    1. Make sure "Visual Studio Editor" ( a.k.a. Visual Studio Tools for Unity) is installed in Package Manager.
    2. Go to Edit > Preferences > External Tools and make sure that Visual Studio is set as your "External Script Editor".
    3. Restart both Unity and Visual Studio, or even your whole machine to make sure.

    9 times out of 10, that will resolve your issue.