raycast destroying player?

ive made a script that is supposed to destroy a gameobject if the gameobject is clicked on (using raycast and Destroy) but no matter where I click on screen it destroys the player object

if (Input.GetMouseButtonDown (0)) {
			Vector3 c = Camera.main.ScreenToWorldPoint (Input.mousePosition);
			RaycastHit2D hit2d = Physics2D.Raycast (transform.position, c - transform.position);
			if (hit2d.collider.gameObject != null) {
				Destroy (hit2d.collider.gameObject);
			}
		}

You could use something like an if statement to check if the name of the hit gameobject is your player, and if it is then don’t destroy the gameobject. Another thing you could do is to check if the gameobject you hit is the one you want to destroy by cross referencing it’s name as well. However, checking the name every frame is not recommended, so you should do something like this.

if (Input.GetMouseButtonDown (0)) {
Vector3 c = Camera.main.ScreenToWorldPoint (Input.mousePosition);
RaycastHit2D hit2d = Physics2D.Raycast (c, Camera.main.transform.forward);
if (hit2d.collider.gameObject != null) {
Destroy (hit2d.collider.gameObject);
}
}

You want the ray to start at the mouse and go directly into the screen right? use this instead.