Question by
unity_nBbvlFOPxdAbWw · Apr 19, 2018 at 07:20 PM ·
guinetworkingmultiplayeronguihost
Why is my GUI popup showing up for both host and client?
Hi,
I'm a beginner in Unity and got stock in a very annoying issue. I hope someone could help me out.
I have a tank multiplayer game and would like the player to see a popup screen, when the player collides with an object. The problem is that the popup appears for all the players both host and client. I would only like to show it for one player who collides with the object.
My onCollision script is attached to the screen object
Even tho i've used NetworkView it is still not working. The code is very simple, i don't know what i have done wrong.
public class OnCollision : NetworkBehaviour
{
bool showGUI = false;
NetworkView nView;
private void OnCollisionEnter(Collision collision)
{
// ... and find their rigidbody.
Collider collider = collision.collider;
Rigidbody targetRigidbody = collider.GetComponent<Rigidbody>();
// If they don't have a rigidbody, go on to the next collider.
if (!targetRigidbody)
return;
// Find the TankHealth script associated with the rigidbody.
nView = targetRigidbody.GetComponent<NetworkView>();
if (nView == null)
return;
if (nView.isMine)
showGUI = true;
}
private void OnCollisionExit(Collision collision)
{
if (nView.isMine)
showGUI = false;
}
private void OnGUI()
{
if (showGUI)
{
if(nView.isMine)
GUI.Box(new Rect(100, 100, 100, 100), "hey");
}
}
}
Thank you in advance, and sorry for my poor language.
capture.jpg
(141.0 kB)
Comment