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

way to detect the operating system?

Discussion in 'Scripting' started by crazybeek, Sep 2, 2015.

  1. crazybeek

    crazybeek

    Joined:
    Aug 23, 2012
    Posts:
    45
    I would like to find which os our game is running on.
    I need to know if it's running on Windows 10 or not basically.
    SystemInfo.operatingSystem leaves me with just a string and not a way to find all possible options.

    Reason
    All major controllers seem to use different axis and buttons on Windows 10.
    makes our default controller scheme run without issues on Win vista, 7 and 8 but not on win10.
     
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,384
    What options are you expecting? They're only running one Operating System, just use a string compare on the return.
     
  3. Duugu

    Duugu

    Joined:
    May 23, 2015
    Posts:
    241
    Last edited: Sep 2, 2015
    Westland likes this.
  4. DarthHawk13

    DarthHawk13

    Joined:
    Feb 24, 2016
    Posts:
    63
    Check out this documentation page:
    https://docs.unity3d.com/ScriptReference/RuntimePlatform.html

    The links for the individual operating systems on that page show how to detect which OS/platform the compiled application is running on.



    Code (CSharp):
    1. if (Application.platform == RuntimePlatform.OSXPlayer)
    2.        {
    3.            //do something
    4.        }
    5.  
    6. else if (Application.platform == RuntimePlatform.WindowsPlayer)
    7.         {
    8.            //do something
    9.         }
    10.  
    11.   else if (Application.platform == RuntimePlatform.LinuxPlayer)
    12.         {
    13.             //do something
    14.         }
    15.  
    16. else if(Application.platform == RuntimePlatform.PS4)
    17.         {
    18.             //do something
    19.         }
    20.  
    21. //and so on
     
    nsteffine likes this.
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    The OP wasn't asking how to find if they were running Windows or not, but which version of Windows.

    The best solution to the OP's issues today is to probably just use the Rewired asset to handle any controller differences and move on to some other problem.
     
    Westland likes this.
  6. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,903
    Why would you necro this and give very wrong advice on multiple levels?
     
    Bunny83, Joe-Censored and TheDevloper like this.
  7. DarthHawk13

    DarthHawk13

    Joined:
    Feb 24, 2016
    Posts:
    63
    The original question was:
    "way to detect the operating system?"

    I found this post because I was searching for a way to detect the OS for different reasons than the original poster. I did read everything. I decided to post what I did because it may help others in the future. This post comes up in search results for other things besides trying to connect a controller to Windows 10. Just trying to be helpful.

    And this offends you Lurking-Ninja? If you are a moderator and you're offended feel free to delete my post. It won't bother me.
     
    Last edited: Oct 28, 2021
  8. gashadokuro

    gashadokuro

    Joined:
    Jan 16, 2016
    Posts:
    4
    You omitted the reason op gave for their topic which specifically states it's a windows issue. As to why you left that out is beyond me.


    Reason
    All major controllers seem to use different axis and buttons on Windows 10.
    makes our default controller scheme run without issues on Win vista, 7 and 8 but not on win10
     
  9. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,903
    No, that wasn't the original question.
    That you don't read the six years old question and give faulty and straight out bad advise? No, but baffles me.
    Do you see "Moderator" badge under my avatar here? I guess you read these things like you read the OP.
    I don't know what you think about our moderators, but they aren't deleting or closing threads because they are offended. They do it when the thread/posts affect other forum visitors. Not because of their personal viewpoint. Please give them the proper respect by thinking first about what you imply, they deserve it.
     
    Westland and Bunny83 like this.
  10. VResearch

    VResearch

    Joined:
    Jan 6, 2021
    Posts:
    18
    For those of you who stumbled upon this forum. I couldn't find a proper solution anywhere and this is what I ended up with:

    using System;

    public void CheckWindowsVersion {
    OperatingSystem os = Environment.OSVersion;
    if (os.Version.Major == 10) { // Running on Windows 10 } else
    else if (os.Version.Major == 11) { // Running on Windows 11 } } }