Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question #if UNITY_STANDALONE_WIN doesnt working?

Discussion in 'Scripting' started by unity_z6OiY8qnWZNTDQ, Jun 7, 2023.

  1. unity_z6OiY8qnWZNTDQ

    unity_z6OiY8qnWZNTDQ

    Joined:
    Mar 23, 2021
    Posts:
    4
    hello I need help

    I'm trying to use the "#if UNITY_STANDALONE_WIN" detection system as it says in the manual (https://docs.unity3d.com/2022.3/Documentation/Manual/PlatformDependentCompilation.html)

    however, the IF code doesn't work and leaves my code completely disabled. all in grey. I've looked in several tutorials and I can't get it to work correctly. Does anyone know what it could be? I use version 2022.3.0 LTS

    Code (CSharp):
    1. using System.Diagnostics;
    2. using System.Globalization;
    3. using UnityEngine;
    4.  
    5. public class _Initialization : MonoBehaviour
    6. {
    7.     private string GetDebuggerDisplay()
    8.     {
    9.         return ToString();
    10.     }
    11.  
    12.     private void Start()
    13.     {
    14. #if UNITY_STANDALONE_WIN
    15.         CultureInfo currentCulture = CultureInfo.CurrentCulture;
    16.         string languageCode = currentCulture.TwoLetterISOLanguageName;
    17.         Debug.Log(languageCode);
    18. #endif
    19.     }
    20.  
    21. }
    upload_2023-6-6_20-4-39.png
     

    Attached Files:

  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    Looks correct to me. Are you set to Windows builds in Unity? Make sure you build settings in Unity is targeting windows.
    upload_2023-6-6_18-41-51.png
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Also make sure it's not just a case of Visual Studio not getting the message.

    Like type some gibberish in the gray code and see if Unity howls in anger.

    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 VSCode package inside of Unity: Window -> Package Manager -> Search for Visual Studio Code Editor -> Press the Update button

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

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    True, I've sometimes switched build targets and VS doesn't grey out or colorize the proper code. Usually just closing VS and opening it will fix it when it gets like this.
     
  5. unity_z6OiY8qnWZNTDQ

    unity_z6OiY8qnWZNTDQ

    Joined:
    Mar 23, 2021
    Posts:
    4

    Thanks, but none of the answers helped me. I looked at deep links, but without success.

    The strange thing is that this code works normally in version 2021.3.17f1.
     
  6. unity_z6OiY8qnWZNTDQ

    unity_z6OiY8qnWZNTDQ

    Joined:
    Mar 23, 2021
    Posts:
    4
    did not work. Tried restarting, reinstalling, redoing everything. nothing worked
     
  7. unity_z6OiY8qnWZNTDQ

    unity_z6OiY8qnWZNTDQ

    Joined:
    Mar 23, 2021
    Posts:
    4
    well... I'm going back to the 2021 LTS version while I wait for new updates.
    I thank everyone
     
  8. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,057
    It works just fine to me
    upload_2023-6-7_12-21-31.png

    I normally use Rider, but I've booted up VS just to check up on it.
    Make sure the Visual Studio Editor package is updated.
    Make sure that Visual Studio itself is fully up to date.

    Close visual studio if it is open.
    Go to the Editor Preferences External Tools and make sure that Visual Studio is selected.
    upload_2023-6-7_12-23-37.png

    Also the click the Regenerate project files button.
    After that open up any script from the project window.

    You can wait a long time on 2021 LTS but it seems to work just fine in 2022 LTS and doesn't need fixing.