Make melee attack in 2D game

Hello guys, I’m trying to add a melee attack to my 2D game.

I wrote this, because I think I should change the center of the mass of the sword because it should rotate as if the player hold it from the grip. The problem is that the centerOfMass set method is not implemented yet, so I don’t know how to make this. Any hint?

public class StuffController : MonoBehaviour {

public KeyCode action;

bool hit=false;
float goBack = 0;
float rate = 0.2f;

void Start(){
	Debug.Log(""+rigidbody2D.centerOfMass);
	
	rigidbody2D.centerOfMass = new Vector2 (0.6f, 0.5f);
	
	Debug.Log(""+rigidbody2D.centerOfMass);

}
void Update () {

	if (Input.GetKeyDown (action) && !hit) {

		rigidbody2D.MoveRotation (-60);
		goBack = Time.time + rate; 
		hit= true;
	
			} 
	else if (hit && Time.time > goBack) {
		hit=false;
		rigidbody2D.MoveRotation(60);

	}

}

}

You can try set it directly Unity - Scripting API: Rigidbody2D.centerOfMass