cast GameObject to light

I’m trying to get a specific light by it’s tag.

    private Light theSun;

    void Awake()
    {
        theSun = GameObject.FindGameObjectWithTag("Sun") as Light;
    }

i’m getting the error “‘UnityEngine.GameObject’ to ‘UnityEngine.Light’ via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion”. What is the proper way to cast the GameObject to a light? Is there a better way to do this all together? Thanks.

Light is a component. You’ll need to do a GetComponent, not cast it.

theSun = GameObject.FindGameObjectWithTag("Sun").GetComponent<Light>();