Destory Bullet on hit

it aint working what i gota do

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


[RequireComponent(typeof(Rigidbody2D))]
public class BulletScript : MonoBehaviour
{
    public float speed;
    public new Rigidbody2D rb { get; private set; }
    public AudioSource ballAudioSource;
    public AudioClip bleep;

    private void Awake()
    {
        this.rb = GetComponent<Rigidbody2D>();
    }

    private void OnTriggerEnter2D(Collider2D hitInfo)
    {
        Debug.Log(hitInfo.name);
        Destroy(gameObject);
    }

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

How to understand compiler and other errors and even fix them yourself:

https://discussions.unity.com/t/824586/8

Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

The complete error message contains everything you need to know to fix the error yourself.

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

there is no error message its just my bullet wont destory on collision (im in 2D btw)

Search about difference between OnTrigerEnter and OnCollisionEnter.
OnTriggerEnter will only occur if at least one of the colliding objects has IsTrigger checked

1 Like
1 Like