How to disable and change shadow type in quality settings or in light component via scripting c# ?

I’m using Unity 5.4 and I wish to enables disable, and choose none, hard or soft via scripting for a windows desktop build game. I was looking to other post with no results. I understand the documentation manual but I do not understand the Unity scripting section side. So also if you can explain how to read the scripting manual in this particular case, can help me.
QualitySettings or Light do not looks like have a shadow or shadow type. Finally there is this LightShadows but I do not know how to set it.

I try:
QualitySettings.shadows.None;

LightShadows.None;

Light.shadowTypes.None
Light.type

My code:

public enum ShadowsRenderType
{
    none,
    fastHard,
    slowSoft
};

public class ShadowSettings : MonoBehaviour {

    public Light sun;
    public ShadowsRenderType shadowsRender;

    void Awake ()
    {
        switch (shadowsRender)
        {
            case ShadowsRenderType.none:
                //QualitySettings.shadows.None; ?
                break;

            case ShadowsRenderType.fastHard:
                //LightShadows.Hard;
                break;

            case ShadowsRenderType.slowSoft:
                //sun.LightShadows.Soft; ?
                break;

            default:
                Debug.LogWarning("PROBLEM" + "\n do not exist");
                break;
        }
    }

You have to set all shadow lights to soft shadows and then you can use QualitySettings.shadows as shown below.
Or instead of ShadowsRenderType you can already use ShadowQuality and assign this directly.

public enum ShadowsRenderType
{
    none,
    fastHard,
    slowSoft
};

public class ShadowSettings : MonoBehaviour {

    public Light sun;
    public ShadowsRenderType shadowsRender;

    void Awake ()
    {
       
switch (shadowsRender)
       {
           case ShadowsRenderType.none:
               QualitySettings.shadows = ShadowQuality.Disable;
               break;

           case ShadowsRenderType.fastHard:
               QualitySettings.shadows = ShadowQuality.HardOnly;
               break;

           case ShadowsRenderType.slowSoft:
               QualitySettings.shadows = ShadowQuality.All;
               break;

           default:
               Debug.LogWarning("PROBLEM" + "\n do not exist");
               break;
       }
    }

OK! so if is Unity 5.5

Unity 5.5

QualitySettings.shadows = ShadowQuality.Disable;

if is Unity 5.4 QualitySettings.shadows = ShadowQuality.Disable will not work. I Was using Unity 5.4.3. So an alternative can be:

// for the specific light
sun.shadows = LightShadows.None;

Thanks for the greate help!

Both should work on most recent Unity versions. sun.shadows is specific for one light source, QualitySettings.shadows is global, you can use both methods.

1 Like