Okay here’s the code from my Enemy C# script and a screen shots of the inspector for one of the cubes exhibiting the issue before and during runtime.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
[SerializeField] GameObject deathVFX;
[SerializeField] GameObject hitVFX;
[SerializeField] Transform parent;
[SerializeField] int scorePerHit = 15;
[SerializeField] int hitPoints = 4;
ScoreBoard scoreBoard;
void Start()
{
scoreBoard = FindObjectOfType<ScoreBoard>();
AddRigidbody();
}
void AddRigidbody()
{
Rigidbody rb = gameObject.AddComponent<Rigidbody>();
rb.useGravity = false;
}
void OnParticleCollision(GameObject other)
{
ProcessHit();
if (hitPoints <1)
{
KillEnemy();
}
}
void ProcessHit()
{
GameObject vfx = Instantiate(hitVFX, transform.position, Quaternion.identity);
vfx.transform.parent = parent;
hitPoints--;
scoreBoard.IncreaseScore(scorePerHit);
}
void KillEnemy()
{
GameObject vfx = Instantiate(deathVFX, transform.position, Quaternion.identity);
vfx.transform.parent = parent;
Destroy(gameObject);
}
}