Hello,
I have two scripts. One checks when the game object collides with “PlayerWithWeapons”.
var Phealth=0;
function OnControllerColliderHit (hit:ControllerColliderHit)
{
Debug.Log(“Collision”);if (hit.gameObject.name == “PlayerWithWeapons”)
{
Phealth=Phealth-5;
Debug.Log(Phealth);
}
}
And the other is attached to the PlayerWithWeapons and is controlled by the player.
var Phealth = 0;
function OnGUI () {
if (GUI.Button (Rect (10,10,150,100), Phealth.ToString())) {
print (“You clicked the button!”);
}
}
I want it so when whatever object the first script is attached to collides with “PlayerWithWeapons” it subtracts 5 from Phealth and displays the correct number on the GUI button on the player characters screen. When I run it, it doesn’t change the value displayed when the objects collide. I believe I have to pass the variable 'Phealth" to the other script but I’m not sure how to do that. So how would I be able to solve this problem?
Thanks