How to assign 2 variables to 2 players in 1 script (hard to really describe the problem, j...just read it)

So, this is quite a hard thing to describe in the question name, I’m really sorry if it’s long and inaccurate. Anyway:

I’ve got 2 players in a game. Both have a collider and a series of attacks that draw a ray.
There is a script in which I make them do specific animations depending in the button pressed and there is one function which plays an animation only when one player is hit by another. Basically, imagine your common fighting game and when one punches the other, the other bends from pain.

I started working with making the health bars for them, again, in a fighting game manner, and succeeded to make a variable playerhealth and in one function wrote many if statements that make a GUITexture change in lenght. It looks something like if{playerhealth==75f){change the image to represent that health}. It all works and I have no trouble in those statements, but the tricky thing is this: in the inspector FirstPlayer has a public texture to which I assign the health bar image and when the FirstPlayers collider ir touched by other players ray he plays the needed animation and his health bar also changes. Then I opened the SecondPlayer in inspector and opened the same script they both share, but there the GUITexture was not assigned, so I assigned another one. Now, this is where the problem begins:

FirstPlayer hits the other one and the texture behaves as the one of the FirstPlayer.

So, I need a way to count the health of both characters individually. Thought of making separate scripts, assign them to the players and inside them call the function to play the animation of the one who was hit and then add the repositioning ifs to change the healthbar. When I did that or very similarly, I received an error which said I can’t use the function because the script security level is high.

I tried to make it as clear as I can.

You don’t need two different scripts: each script assigned to an object becomes an independent instance, thus their variables are also independent - playerhealth exists in both players, and may have different values.

It seems that your problem is the scope of functions or variables: if you don’t declare a variable or function public in C#, it’s assumed to be private and you can’t access it from other scripts - an error message like the one you’ve described will appear.

Declare the problematic function as public and probably the error will be over - if not, post the script where the error occurs and/or the one where the function is declared.