I’m sure you will get this work if you stick with it. You’ve always been polite, and you’ve worked on this for months. Other people would have given up after a few minutes. That’s why I’m still helping you because I want you to make this work.
It wouldn’t make sense to explain what I trying to do then I would be repeating myself.
The problem is the following: You had a problem with the GameController. Then, suddenly, you had another problem. I don’t even remember if you ever told me whether the initial issue is fixed. Since I reply to lots of students on a daily basis, I sometimes lose track of a student’s current issue when there are multiple issues in the same thread. For this reason, I asked you to briefly describe your current problem. It’ll help me because I don’t have to guess what your issue is/was. And it’ll help you because we can focus on your current issue.
When I want to solve an issue in my project, I always break the problem down into single, managable tasks/problems. I complete each task step by step, and that automatically fixes the initial problem. (Hopefully.)
Your health bar is a complex problem. You already have the relevant components, which is half of the solution. However, they don’t interact with one another correctly yet, which is the missing half. Do you really want to give up even though you already solved half of your problem?
Here are a few steps:
- Click on the Player game object.
- Check its Inspector.
- Does its Inspector have a script attached that is supposed to handle the incoming collision? If not, add one.
- Open that script.
- Check the spelling of the OnParticleCollision method. Compare it to the API, not to my answer.
- Add a meaningful Debug.Log to that method.
- Test your game.
- Does the message appear? If not, check the collider of the Player game object. Is it enabled? Is it a non-trigger? If so, continue with step 9.
- Make sure the “Player” tag attached to the same game object as the Player’s collider.
- Make sure the enemy’s particle system interacts with the “Player” layer.
Does the message you wrote in step 6 finally appear?
If in doubt, print out my list and tick off the single tasks once you completed them. Do not skip any step.
Collision detection is always a bit tricky because neither you nor I have all the information about what is happening inside Unity. Most of Unity is not open-source.
Once the collision message appears, your healthbar might work. If it does not, you will have to check if the damage is processed correctly. This is fairly easy to debug because this does not have anything to do with Unity but with your script(s) only. You know your scripts because you wrote them. They represent your logic, and there are no secrets.