The collided settings in lecture 100 do not work on my emeny ships how to fix?

[Question]The collided settings in lecture 100 do not work on my enemy ships how to fix?

Martin · 14 minutes ago

All my enemy ship triggers are all on check in the collider boxes but bullets still bounce off them But don’t know what my enemies don’t die after a bullet hits them? and I don’t know how to get rid of this error message once and for all? Thank you for any guidance. This is how my game plays now
https://www.dmmsdi.com/prss/index.html
I updated my game on the server if you want to see how it plays now?

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

public class Enemies: MonoBehaviour
{
    // Use this for initialization
    void Start()
    {
        Collider boxCollider = gameObject.AddComponent<BoxCollider>();
        boxCollider.isTrigger = false;
    }
    void OnParticleCollision(GameObject other)
    {
        Destroy(gameObject);
    }
}

Hi Martin,

What does your code look like within Enemy.cs? Can you copy/paste it up and apply the code formatting please.

Also - you say lecture 105, but that’s an Instructor Hang Out, are you sure that’s the lecture number you mean?


See also;

Hi Rob, Thanks for replying I made a mistake with the lecture # it’s actually 100. I also added my c# code for Enemies to my post. I notice an error in the code when replying to you. I will let you know if it helped I had space in the ( Enemies : ) I fixed this just now. Any feedback is appreciated. :slight_smile:

Hi,

The space in this line;

public class Enemies: MonoBehaviour

doesn’t matter, you can have it or not have it.

If you are still running into problems, share your project files and I will be happy to take a look.

The forum will allow uploads of up to 10MB, if your project files (zipped) are larger than that you would need to use a service such as Google Drive or Dropbox, and then share the URL.

Hi Rob, Thanks I was able to fix this but I needed to add the enemies script to each enemy child listed under the enemies game object in the Hierarchy is that okay? because Ben only has the enemy script on the enemy game object, not every enemy ship like I have to do to get it to work. Any Feedback is appreciated :wink:

1 Like

Hey,

Each enemy would require this script. You would be adding a box collider to each individual enemy, you would also be wanting to destroy each individual enemy - if you placed this script on a parent GameObject which contained multiple enemies you’d, at best, have them all destroyed at once.

Can you give me the time frame and lecture number where you see Ben doing this differently in the course?

Thank you Rob, for your guidance :slight_smile:

1 Like

You’re very welcome :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms