Flashbang script help

I’m currently working on a Flashbang script… So far it works quite well actually. However, I want to decrease the alpha of the attached canvasGroup if the player isn’t looking straight at the flashbang when it explodes.

Right now, I can look away from the flashbang and don’t go blind, but if I’m within the angle (110) I get fully blinded which is not the effect I’m looking for.

Hope you understand what I mean and what I want to achieve… :slight_smile:

if(Physics.Linecast(transform.position, player.throwPosition.position)) {
            Debug.Log("View blocked");
        } else {
            if(Vector3.Angle(transform.position, player.transform.position) < 110) {
                overlay = Instantiate(overlayImage) as Image;
                canvasGroup = overlay.GetComponent<CanvasGroup>();
                canvasGroup.alpha = 1f;
                overlay.transform.SetParent(_canvas.gameObject.transform, false);
            }
        }

youll have to base the alpha off the angle, so something like this maybe.

float angle = Vector3.Angle(transform.position, player.transform.position);
if(angle < 110) {
    ...
    canvasGroup.alpha = angle/110;
    ...
}