- Home /
Multiplayer game GUI problem
Hi,
i started to work on a simple multiplayer game. Everything I've done so far works great but i have now an issue with the GUI. Every player can see his hp in the right bottom part of the screen. If a player hits another one there's a value in the player script called hp which decreases of a certain amount. The problem is that the GUI.Label i used to show players hp doesn't update the value and the player can't see how much hp remain before dying.
Here's the code i implemented to show a player's hp:
void OnGUI()
{
if(networkView.isMine)
{
GUI.matrix = Matrix4x4.TRS(Vector3.zero,Quaternion.identity,new Vector3(Screen.width/1920f,Screen.height/892f,1f));
GUI.Label(new Rect(1520, 787, 500, 100), "HP: " + (int)hp + " %", style1);
}
}
And here's the code with which the player can hit another one:
if(Input.GetKeyDown(KeyCode.LeftControl))
{
hit = Physics2D.Raycast(transform.GetChild(0).transform.position, new Vector2((Mathf.Cos((transform.rotation.eulerAngles.z)*2*Mathf.PI/360)),(Mathf.Sin((transform.rotation.eulerAngles.z)*2*Mathf.PI/360))) );
if(hit.collider != null)
{
if(hit.collider.tag == "Player")
{
decreaseHp();
}
}
}
void decreaseHp()
{
if(hit.collider != null)
{
hit.collider.GetComponent<JetController>().hp -= damage;
if((int)hit.collider.GetComponent<JetController>().hp == 0)
{
Network.Destroy(hit.collider.gameObject);
}
}
}
This part of the code works perfectly so i don't know why the GUI is not showing the correct value of hp and get stuck on the same initial value.
Can someone help me?
Your answer
Follow this Question
Related Questions
GUI label on raycast? 0 Answers
GUI Not displaying itselfe in Multiplayer lobby 1 Answer
Dynamic Resizing of tooltip to match content? 1 Answer
(GUI.Label) Line spacing issue with wordwrap 0 Answers
Weapon Selection Script 1 Answer