My 2D ojects are not destroying on colliion

Title. I dont know what I did wrong but I am trying to make a brick and ball breaker type of game and its saying an object reference is required for non static field ‘Collision2D.gameObject’ there’s a bit more but thats about it heres my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
public GameObject Player;
public float speed = 3f;
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
float horizontal = Input.GetAxis(“Horizontal”);
float vertical = Input.GetAxis(“Vertical”);
Vector2 position = transform.position;
position.x = position.x + speed * horizontal * Time.deltaTime;
position.y = position.y + speed * vertical * Time.deltaTime;
transform.position = position;
}
void onCollisionEnter2D(Collision2D collision2D)
{
if (Collision2D.gameObject.tag == “Ball”)
{ GameObject.Destroy(Player); }
}
}

Any help would be awesome! Thank you in advance

if (collision2D.gameObject.tag == "Ball") {
    GameObject.Destroy(Player);
}

collision2D with small letter - variable not a Class

And what object this script attach to?

I put it on the Player and my hope is when it hits the ball the player would get destroyed
It works thank you so much
I forgot to check use full kinmatic

1 Like