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