Needing to get communication between two c# scripts.

So I’m currently working on a project that needs to have two c# scripts interact with one another. I have a script that changes the texture of a Gui Texture based on the player’s health, which is a script of its own.
This is the code I have for now that calls it.

if(GetComponent<PlayerHealth>().health >= 4)

I’ve tried having the health int being a Public Static int but that messes up another script. So what am I doing wrong and how can I fix this? Let me know if you want to see the whole code.

Yes, please post your whole code. Most of the experienced users can sit here and tell you all the different ways you can go about doing this, but seeing how you're trying to do it so that we can guide you through the correct manner would be more appropriate.

1 Answer

1

that code is right. Presumably the

health in the script

PlayerHealth
isn’t public

that should work if you have a script called PlayerHealth

with a

Public Int health;