Contradiction in The Box Collider

Alright. So i just finished using the Argon assault as reference and went on in the course to see how Rick would do it and i was triggered none the less lol. When i saw rick slap that box collider on the prefab my half an our of trying to put it on from code went to the drain lol. So here is how i went about it.

On Argon Assault i vividly remember having nightmares over prefabs and constantly breaking my game because i would mess with them and so when Ben explained that when you add things from code to prefabs nothing wrong will happen just like how we added the box colliders and such from code onto the enemy ships. And so i do this and end up struggling because when i go and add a box collider onto the Enemy prefab the box collider is all the way on the floor below the enemy and is scaled at 1, 1, 1.

So now i had 2 options.

  1. figure out how to scale a box colliders center and size so it can match up with the body of the enemy(never figured out how)
    2)Add a seperate script containing the box collider and particle collisions and put it on the body of the enemy.

Finally after 30 minutes or more i finally get the particles to react to the collision but when i coded (destroy(gameobject) it would destroy the Body and not the enemy so the empty enemy would keep moving and the turrets would shoot so instead i did. Destroy(transform.parent.gameObject).

public class AddComponent : MonoBehaviour
{
    [SerializeField] int DmgTaken = 10;

    void Start()
    {
        AddCollider();
    }

    private void AddCollider()
    {
        Collider BoxCollider = gameObject.AddComponent<BoxCollider>();       
        BoxCollider.isTrigger = false;
    }

    void OnParticleCollision(GameObject other)
    {
        ProcessDamaged();
        if (DmgTaken <= 0)
        {
            Destroy(transform.parent.gameObject);
        }
    }

So i have the Mover script on the enemy prefab.

And the script that adds the box collider and collision on the body.

Now im just hoping and praying that the way i did it doesnt have to be changed to keep going into the course cuz i feel pretty discouraged for referencing and typing code when all i had to do was slap a box collider on lol

Privacy & Terms