- Home /
Sending and receiving variables trough network?
Hi there, I've found a few similiar questions, but none of them reflect exactly what I need to know.
Description:
I have 2 gameObjects, "player" and "other", both have a networkView. The "other" object has a String variable called "othervariable".
Problem:
I want do be able to change the "othervariable" in the "other" object trough the network.
What I've tried already:
I tried to call RPC functions, but it didn't work properly, yet. I can change the variables, but I can't receive their values.
I tried OnSerializeNetworkView, I've read the reference but I still don't understand how it could be useful. After creating the function, I tried this in the "player" script:
other.networkView.othervariable = newvalue;
Is it wrong?
I wrote wrong what a I really want to do. I need to make a comparison inside a if, like this: if(other.othervariable == player.playervariable) , the problem is in how I'll be able to read the "othervariable" for making the comparison.
Answer by Anxo · Feb 20, 2012 at 11:31 PM
RPC functions work perfectly for what you are talking about. You can send more than one var via RPC. It does not send over the varible name but it sends over its value.
var hotdogs : int = 10;
if you send hotdogs, you are sending the number 10. on the other side you interet it.
var hotdogs : int = 0;
@RPC
function Howmanyhotdogs( incomingHotDogs : int){
hotdogs = incomingHotDogs;
}
now hotdogs is 10.
you can pass multiple things like
@RPC
function HowmanyHotDogs(incLocation : Vector3, IncAmount : int, incTraveSpeed : float){
then you can use these var locally.
Here is some more info on how to use it. http://unity3d.com/support/documentation/Components/net-RPCDetails.html
Answer by gooncorp · Nov 29, 2013 at 12:05 AM
what your saying works for int, float, but not string. im having the same problem i think its a bug in unity