Not able to toggle isTrigger

I want to to change the platform (which is the water surface) into a trigger when the player hits an obstacle so he falls through underwater. I created an empty game object to act as a game controller and attached my script to it. Tried adding the script to the player and the obstacle too. So far I had no success. I made sure the tags are correct. Any help will be appreciated. Here is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameController : MonoBehaviour

[HideInInspector] public GameObject surface = GameObject.FindGameObjectWithTag("WaterSurface").GetComponent<GameObject>();

void OnCollisionEnter2D(Collision2D collision)
    if (collision.collider.tag == "Obstacle")
        surface.GetComponent<Collider2D>().isTrigger = true;


Note that if you call “FindGameObjectWithTag” during a variable initialization unity throws the following error:

"FindGameObjectWithTag is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead."

Also check if one of your objects has a non kinematic rigidbody. The unity documentation says:

"Collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached."