Skip to main content
2 of 3
added 181 characters in body

Actually Lights does not contain colliders, but what you can do is add a CircleCollider2D component to a light, then track if your object collide with the collider of this light and only then trace a ray from your object (character) to the light, if the ray hits a collider before hitting the light then you know your character is in the shadow part of this light!

I am not sure you could go away with this without using raycast2D, but dont be afraid once you get a hold on it it can be very straight-forward.

For example to put on your character :

private bool inTheShadow = false;

void Update() {
    if(!inTheShadow) {
        //Replace following lines with your own magic
        Debug.Log("Too much Light!!");
    }
    else { Debug.Log("Vampire Secure Area!!"); }
}

void OnCollisionStay2D(Collision2D coll) {
    
    if (coll.gameObject.tag == "Light") {//is that component a light? (need to have the light tag on your light
        RaycastHit2D hit = Physics2D.Raycast(transform.position, (coll.gameObject.transform.position-transform.position).normalized);
        if(hit.collider!=coll) { //Am i hitting the light or smthing else?
            inTheShadow = true;
        }
        else {inTheShadow = false;}
    }  
}

This is a non optimized version done quickly without unity or anything related near hand