Variable has not been assigned?

Having problem getting rid of the error listed below, shows only when I press the Target trigger. Is there any workaround for this? What I’m hoping to achieve is to change selectedTarget upon releasing the trigger. Also appreciate if someone can explain why this is happening.

if (Input.GetAxis("Target") > 0.01f)
{
    // Condition check to prevent from excuting the commands multiple times
    if (targetMode == false)
    {
        targetMode = true;
			
        // Instantiate the targets list on scene
        targets = new List<Transform>();

        // Adding the list of selectable into the targets list
        TargetList();

        // Selecting one of the member from the targets list
        SelectTarget();
    }
    // SelectedRenderer works here
    SelectedRenderer(true);
}
else
{
    // SelectedRenderer doesn't work here and gives the error below
    SelectedRenderer(false);
    targetMode = false;
}

private void SelectedRenderer(bool selected)
{
	if (selected == true)
	{
		selectedTarget.renderer.material.color = Color.blue;
	}
	else
	{
		selectedTarget.renderer.material.color = Color.white;
	}
}

UnassignedReferenceException: The variable selectedTarget of ‘ThirdPersonCamera’ has not been assigned.
You probably need to assign the selectedTarget variable of the ThirdPersonCamera script in the inspector.
ThirdPersonCamera.SelectedRenderer (Boolean selected)(Console points to
‘selectedTarget.renderer.material.color = Color.white;’)

I got this working! This method is in the LateUpdate, I guess the else lines are giving the issue. But I still don’t understand how this is happening, would be happy if someone can shed some light for me here.

else
{
    // Figure out what I need to do is just add a conditional check here
    if (selectedTarget != null)
    {
        SelectedRenderer(false);
        targetMode = false;
        selectedTarget = null;
    }
}