Trying to get a cannon to shoot the player

I’m new to unity and I want to freeze the player when he enters the cannon and on keypress shoots them across the map

public float thrust;
public Rigidbody2D rb;

void Start()
{
   
}

void FixedUpdate()
{
   
}
void OnTriggerEnter2D(Collider2D collision)
{
    if (collision.gameObject.tag == "Player")
    {
        rb.bodyType = RigidbodyType2D.Static;
        if (Input.GetKeyDown(KeyCode.B))
        {

            rb.bodyType = RigidbodyType2D.Dynamic;
            rb.AddForce(new Vector2(0, thrust));
        }
    }
}

But he wont switch to a dynamic rigidbody on the keypress and I cant figure out how to work around it

I spent about 3 days trying to make this script, now that I got it, it has worked well in my project. Here he goes to help anyone looking for the same thing. Remembering that it is for 3D games.

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


public class PlayerControlCannon : MonoBehaviour
{
    public Rigidbody character;
    public Transform shootingPart;
    public bool manualControl;
    public float rotatingSpeed = 100f;
    public float shotForce = 50f;

    private bool isShooting = false;
    private float backColliderDelay = 0.05f;


    public void Start()
    {

    }


    public void Update()
    {

        if (Input.GetButtonDown("Fire1") && isShooting == true)
        {

            StartCoroutine("Shooting");

            print("Fired");

        }
    }

    IEnumerator Shooting()
    {

        character.transform.position = transform.position;
        character.transform.rotation = shootingPart.rotation;

        character.AddForce(transform.forward * shotForce, ForceMode.VelocityChange);

        character.transform.parent = GameObject.FindWithTag("Player").transform;
        character.GetComponent<MeshRenderer>().enabled = true;
        character.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.None;
        character.GetComponent<Collider>().enabled = false;

        yield return new WaitForSeconds(backColliderDelay);

        character.GetComponent<Collider>().enabled = true;

        isShooting = false;

    }

    public void OnTriggerStay(Collider other)
    {
        if (other.gameObject.CompareTag("Player"))
        {

            other.gameObject.transform.parent = transform;
            other.gameObject.transform.localPosition = new Vector3(0f, 0f, 0f);
            other.gameObject.transform.localRotation = Quaternion.identity;
            other.gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
            other.gameObject.GetComponent<MeshRenderer>().enabled = false;

            isShooting = true;

        }

        if (manualControl == true)

        {
            // Move to the right
            if (Input.GetButton("Horizontal") && Input.GetAxisRaw("Horizontal") > 0)
            {
                transform.Rotate(Vector3.up * rotatingSpeed * Time.deltaTime);
            }

            // Move to the left
            else if (Input.GetButton("Horizontal") && Input.GetAxisRaw("Horizontal") < 0)
            {
                transform.Rotate(Vector3.down * rotatingSpeed * Time.deltaTime);
            }

            // Move to the up
            else if (Input.GetButton("Vertical") && Input.GetAxisRaw("Vertical") < 0)
            {
                transform.Rotate(Vector3.right * rotatingSpeed * Time.deltaTime);
            }

            // Move to the down
            else if (Input.GetButton("Vertical") && Input.GetAxisRaw("Vertical") > 0)
            {
                transform.Rotate(Vector3.left * rotatingSpeed * Time.deltaTime);
            }     
        }
    }
}