- Home /
Only one client can see enemy hp bars
Hi, I use photon networking for my game. I instantiate 3 enemies when I start up a server. I use Physics.overlapsphere to detect if a gameObject with tag: Player is inside the overlapsphere.
It works fine on the first connected player, however the second connected player cannot see the enemies' hp bars. When I walk up to the enemies on the second client I can see the hp bars on the first client, not on the second client. That's my problem. I have searched for days for a solution for this. I would really appreciate it if anyone could help me with this. It's driving me crazy.. :(
Collider[] col =
Physics.OverlapSphere(transform.position,
10);
for (int i=0; i<col.Length; i++) {
if(col[i].tag == "Player") {
showHealthbar=true;
float distanceCol = Vector3.Distance(transform.position,
GetComponent().transform.position);
if(distanceCol > 10) {
showHealthbar=false;
}
}
}
Are the healthbars network instantiated? Are they network synced? Whos doing the calculations?
Please put you're code in a Code Sample or paste bin. It is very hard to read when its all mixed up. You would probably want to instantiate the enemys then sync their health. If you need more help just put you're code as a comment and i will be glad to help.
if you see the first player's GUI on the second client, then in the script find the onGUI method which writes the healthbar and put the whole thing in an if like:
void OnGUI()
{
if(photonView.is$$anonymous$$ine)
{
GUI.Label(new Rect(10,10,150,20), health.ToString());
}
}
I have put it in a code sample now. I use gui to show health bar, and I have also network instantiated the enemies. I see no reason to why the other enemy can't see the health bars :o.
Answer by Vetle · Apr 29, 2015 at 12:07 AM
I actually figured it out. I had an if statement: if(enemies != null && enemies[i].showhealthBar) and I figured out that player 2 had the enemies array nulled, it was nothing in it, because it only searched for enemies when player 1 got into the game! So I just put it like this in the Update function: enemies = GameObject.FindGameObjectsWithTag("Enemy");
Now I can finally see hp bars on both clients!
Your answer
Follow this Question
Related Questions
Photon Combat script does not work 0 Answers
PUN Join/Create menu tutorials 0 Answers
Unity3D Photon movement synchronization 0 Answers
Unity Photon Network - Text Mesh Sync 1 Answer
Networking - Move all players to a position? (Photon) 1 Answer