Sorry for posting this again, but objects aren't destroying.

The script for my projectile in the project is;

public class ProjectileScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{

}

public float speed = 100;
void Update()
{
transform.Translate(0, 1 * Time.deltaTime * speed, 0);
}
void OnTriggerEnter (Collider other) {
Destroy(gameObject);
Destroy(other.gameObject);
}
}

Please read the following which shows you to how to help yourself with these kinds of simple problems by debugging. If you’ve already debugged it then posting your results is the bare minimum you can do if you want help.

Also, please edit your post to use code-tags ; don’t post as plain text please.

Finally, note that a code snippet likely doesn’t provide enough information to say what is happening. All you’ve said is that “objects aren’t destroying”. No idea what that means. No idea if they’re even coming into contact and calling that trigger function. Debugging will verify that and you can do it before making a post too.

Hope it helps.

2 Likes

Does your Projectile object actually has a Rigidbody component attached? If not you don’t get any physics interactions from it. Moving objects with a collider always needs to have a Rigidbody component.

I just tried that, but it didn’t work.

You should switch your destroy commands. By destroying the game object that holds the script first, most likely makes that the Destroy(other) never executes.

You can easily debug this by replacing the Destroy(other) with for example Test();
then write a Test function that will write some text to the Console.

Actually, I saw in a discord server it was because it was a 2d project.