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 iDesign · Jul 30, 2014 at 07:06 PM · guiphotondisplay

Display only for one player

I have the following code which displays a GUI when an object collides with the Player. I am using the Photon Viking Demo from the Asset store, an when I add this code to an object, the GUI displays for all players in the Scene. I would like it to only display for the player that it collided with.

   var showGUI = false;
   
   function OnCollisionEnter (col : Collision)
   {
         if(col.gameObject.tag == "Player") 
         {
           showGUI = true;
         }
   }
    function OnGUI () {
    if (showGUI) {
         GUI.Box(new Rect(100,100,100,100),"hey"); 
    }
   }

I assume retrieving the Player's name from Photon might help,

 if(col.gameObject.name == GetComponent(PhotonView).owner.name) 
     

But that hasn't worked either.

I hope that someone can help me here!

Comment
Add comment · Show 8
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 iDesign · Jul 31, 2014 at 06:34 AM 0
Share

Same problem, but he hasn't received an answer either: http://answers.unity3d.com/questions/668534/photon-multiplayer-viking-gui-only-visible-to-each.html

avatar image RedDevil · Jul 31, 2014 at 06:39 AM 0
Share

that code works perfectly.It should only display it for Player and it does that but you have alot of players in the scene..and the code was made for only 1 player

avatar image Arcadewiz · Jul 31, 2014 at 06:42 AM 0
Share

Where exactly are you disabling the GUI. It seems that the boolean showGUI is always 'true' once it is triggered. your conditions aren't clear from what you posted.

avatar image iDesign · Jul 31, 2014 at 06:53 AM 0
Share

@RedDevil yes I know it works, I am trying to find a fix to have it display for only the player that collides with it (even if there are multiple players in the scene)

@Arcadewiz, it's not a matter of the code, it works fine (and the boolean is initially set to false?). I just need to know how to have the GUI display for the player that collides with the object (not for all players in the scene like it is currently doing).

avatar image RedDevil · Jul 31, 2014 at 06:57 AM 0
Share

if this is a multiplayer game and you have 2 types of enemys the easyer fix would be to have diferent tags

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by flota113 · Jul 31, 2014 at 08:11 AM

You could probably use PhotonView.IsMine I think that this answer http://answers.unity3d.com/questions/439600/photonview-controlling-multiple-fps-controllers.html could also help You ;)

Comment
Add comment · Show 19 · 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
avatar image iDesign · Jul 31, 2014 at 01:59 PM 0
Share

Nearly there! Did I put the code in the wrong place? I get the error: Insert a semicolon at the end.

 var is$$anonymous$$e = false;
 var showGUI = false;
   
   function Start() 
   {
   PhotonView pv = PhotonView.Get(this); // line with error
  
    if (pv.is$$anonymous$$ine)
    {
     is$$anonymous$$e = true;
    }
    else
    {
     is$$anonymous$$e = false;
    }
   }
   function OnCollisionEnter (col : Collision)
   {
     if(col.gameObject.tag == "Player") 
       {
         showGUI = true;
       }
   }
  function OnGUI () {
    if (is$$anonymous$$e) {
     if (showGUI) {
         GUI.Box(new Rect(100,100,100,100),"hey"); 
     }
    }
   }

avatar image flota113 · Aug 02, 2014 at 04:46 PM 0
Share

Sorry it didn't show me that you commented :/ I think that you mixed C++ with JS ;)

 PhotonView pv = PhotonView.Get(this);

I guess it should be:

 var pv = PhotonView.Get(this);

but I have never done anything in JavaScript in Unity, so I can be wrong ;)

avatar image iDesign · Aug 02, 2014 at 05:06 PM 0
Share

Np! Thanks for pointing that out, though now I get the error:

 $$anonymous$$ identifier: 'PhotonView'. 

Any ideas?

avatar image flota113 · Aug 02, 2014 at 05:58 PM 0
Share

Yes, I have one, but again I don't use JavaScript, so treat it with caution ;)

  public class networking extends Photon.$$anonymous$$onoBehaviour {
    
  var is$$anonymous$$e = false;
 var showGUI = false;
 function Start()
 {
 
 var pv = gameObject.GetComponent(PhotonView).Get(this); // line with error
  
 if (pv.is$$anonymous$$ine)
 {
 is$$anonymous$$e = true;
 }
 else
 {
 is$$anonymous$$e = false;
 }
 }
 function OnCollisionEnter (col : Collision)
 {
 if(col.gameObject.tag == "Player")
 {
 showGUI = true;
 }
 }
 function OnGUI () {
 if (is$$anonymous$$e) {
 if (showGUI) {
 GUI.Box(new Rect(100,100,100,100),"hey");
 }
 }
 }
 }


You have to also copy Plugins folder from "Photon Unity Networking" to the Assets folder(just drag it with mouse ;) )

avatar image iDesign · Aug 02, 2014 at 06:59 PM 0
Share

I really appreciate your help! Apparently, I need to use C# ins$$anonymous$$d of Unity Script (JS), I get exactly the same errors after I drag the Plugins folder as the guy in this forum: http://forum.exitgames.com/viewtopic.php?f=17&t=2634

Do you know how to convert the code? I figure maybe changing the variables and all the "functions" to "voids" should work, but I don't have much knowledge of C#.

Show more comments

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Displaying varying text 1 Answer

GUI Overlay Display 0 Answers

Why does the font selected for my GUI Skin not display correctly? 1 Answer

Make accented letters show in text field on Android? 2 Answers

Problem| Player Name Above The Player 2 Answers


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