- Home /
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!
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
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
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.
@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).
if this is a multiplayer game and you have 2 types of enemys the easyer fix would be to have diferent tags
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 ;)
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");
}
}
}
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 ;)
Np! Thanks for pointing that out, though now I get the error:
$$anonymous$$ identifier: 'PhotonView'.
Any ideas?
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 ;) )
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#.
Your answer
Follow this Question
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