I was making a simple game. It is a game about clicking to shoot squares at a rectangle and the squares get destroyed after touching the rectangle but the squares don’t get destroyed
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
void OnCollisionEnter2D(Collision2D coll)
{
if(coll.GameObject.FindWithTag("Player"))
{
Destroy(gameObject);
}
}
public Rigidbody projectile;
public float speed = 4;
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
Rigidbody p = Instantiate(projectile, transform.position, transform.rotation);
p.velocity = transform.forward * speed;
}
}
}
I do not know what is wrong because I am a beginner