I am doing the M2H tutorial and playing with code as I go along. Now im trying to get data sent by the other player to be shown on GUI. The prints show that the data is received, but it won’t show up on the GUI. What am I doing wrong here? I cant even get it working with the RefreshGUI()-function I made.
var hits : int = 0;
var hitsEnemy : int = 0;
var hitsReceive : int;
var testInt : int;
function Awake(){
if(!networkView.isMine){
enabled=false;
}
}
function Update(){
if(networkView.isMine){
if(Input.GetKeyDown("space"))
hits++;
}
}
function OnGUI(){
if(networkView.isMine)
{
print("TestIntGUI: " + testInt);
print("HitsEnemy: " + hitsEnemy);
GUI.Box( Rect(100,100,150,20), "Hits: " + hits);
GUI.Box( Rect(200,200,150,20), "TestInt: " + testInt);
GUI.Box( Rect(150,150,150,20), "hitsEnemy: " + hitsEnemy);
}
}
function OnSerializeNetworkView(stream : BitStream, info : NetworkMessageInfo)
{
if (stream.isWriting)
{
var hitsSend = hits;
stream.Serialize(hitsSend);
}
else
{
stream.Serialize(hitsReceive);
testInt = hitsReceive;
RefreshGUI();
print("TestInt(Streamed): " + testInt);
}
}
function RefreshGUI(){
print("I was called!");
hitsEnemy++;
print("Function: " + hitsEnemy);
}
I removed the networkView.isMine from everywhere including the Awake(). Now it works as other player can see the other’s hits. I am just learning Unity3D networking, thus I cannot understand why. Could someone explain to me why it wasnt working and why it is working now? Thank you.
In the Awake you were telling the script to disable itself when the player wan’t the owner of the view. in the other functions you were saying :
if i own the view… do this…
so for some reason your request wasn’t hitting the booleans.
it’s been to long ago i used unity’s networking to debug further but i’m guessing it has to do with the networking setup ( authoritative or not )