How can Script Tell if it's in Web Player vs. Standalone?

QUESTION: Does the Script API provide a way for our scripts to determine if we're running in the WebPlayer?

In our project, we are deploying to both WebPlayer as well as Standalone (PC). In PC mode, we are interacting with some Windows/.NET based DLL's via the DLL PInvoke methods described in your documentation. This is working great for Standalone(PC) mode.

However, when we try to run in WebPlayer -- the application just freezes up. Nothing works. The only way to get it to work is to DISABLE the MonoBehaviors that are accessing the .NET DLL's.

I'd like to DISABLE these behaviors during script initialization, for WebPlayer only. If you can tell me how to determine when we're running inside the WebPlayer, then I can do this, and we'll be very happy! :)

Check the value of Application.platform:

 if( Application.platform == RuntimePlatform.OSXWebPlayer
     || Application.platform == RuntimePlatform.WindowsWebPlayer )
 {
     ...
 }

If you don't want to differentiate on platform, you can also use Application.isWebPlayer which returns true if you run under the web player on any platform.

This is what I do, for the reasons stated in the comments:

// Play nice with the web player, if this is a web player build
if (Application.isWebPlayer) {
    Security.PrefetchSocketPolicy(EsIp, EsPort); // Hangs the stand-alone player
};

Via Application.platform.

As of Unity 5.4+ (2016), the top answer is no longer supported.

Please see examples below for what works now (as of 11-Jul-2022):

Debug.Log("Current platform: " + Application.platform); // get current platform type
if (Application.platform == RuntimePlatform.WebGLPlayer)
{
    // do the thing for web GL platform
}
else if (Application.platform == RuntimePlatform.WindowsEditor)
{
    // do the thing for when working in Windows Editor
}
else if (Application.platform == RuntimePlatform.OSXEditor)
{
    // do the thing for when working in Mac OS X Editor
}
else if (Application.isConsolePlatform)
{
    // do the thing for console platforms
}
else if (Application.isEditor)
{
    // do the thing for when in Unity Editor mode as oppose to a specific editor (see above if statements)
}
else if (Application.isMobilePlatform)
{ 
    // do the thing for mobile platform
}

References:

More Application methods:

More platform types: