Search Unity

Unity Application.Platform in Live App

Discussion in 'Scripting' started by mholmes, Mar 20, 2021.

  1. mholmes

    mholmes

    Joined:
    Dec 8, 2012
    Posts:
    414
    I'm building a switch statement I just need to know what I'm looking for in my switch

    snippet:
    Code (CSharp):
    1.  
    2. string type = Application.platform.ToString();
    3. switch(type)
    4.         {
    5.             case "Windows":
    6.                 break;
    7.             case "Linux":
    8.                 break;
    9.             case "Mac":
    10.                 break;
    11.             case "Android":
    12.                 break;
    13.         }
    Just need the correct verbiage. Of course because its a string has to be exact words. Could not find it in docs Sure its something simple.
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    Why are you converting it to a string? Enums work fine in switch statements.
     
  3. mholmes

    mholmes

    Joined:
    Dec 8, 2012
    Posts:
    414
    Ok what are the values then for enum? I need to detect it from a "live" perspective
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,727
    I am going to let you go look in the documentation for
    Application.platform
    so you understand where these enums come from and can help yourself directly, without me retyping it all for you.
     
  5. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    Find the return type of Application.platform, and then look up that type. (You can easily do both of those things either on Unity's scripting API web page, or in Visual Studio using their smart context.)
     
    Kurt-Dekker likes this.