Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Vetle · Apr 07, 2015 at 01:35 AM · c#multiplayerphoton

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;
                                  }
                  
                              }
                  
                  
                          }
 


Comment
Add comment · Show 9
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Vetle · Apr 09, 2015 at 01:21 AM 0
Share

anyone? Please.

avatar image Lilbob · Apr 18, 2015 at 03:26 PM 1
Share

Are the healthbars network instantiated? Are they network synced? Whos doing the calculations?

avatar image InfernoZYB · Apr 24, 2015 at 03:43 AM 1
Share

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.

avatar image hbalint1 · Apr 27, 2015 at 09:32 AM 1
Share

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());
     }
 }
avatar image Vetle · Apr 27, 2015 at 09:32 AM 0
Share

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.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges