- Home /
Passing a variable to other Players
In my game I need to share a variable (a Seed to generate a Map) to all other Players connected, I already wrote a sort of code but it doesn't seem to work, what's wrong?:
using UnityEngine;
using System.Collections;
public class RandomSeed : MonoBehaviour {
public static int randomSeed;
// Update is called once per frame
void Update () {
if(NetworkManager.multiPlayer){
if(Network.isServer){
randomSeed = Random.Range(33, 6574839);
networkView.RPC("SetSeed", RPCMode.All, randomSeed);
canModify = false;
}
}
}
[RPC]
void SetSeed(int newSeed){
randomSeed = newSeed;
}
}
I get really confused when trying to code with RPC, is the problem in the RPC part?
Answer by azmat786n · Dec 26, 2013 at 04:21 PM
//Script 1
//void should be public or static
public void SetSeed(int newSeed) {
//set newSeed to some vars as you like
}
//Script2
void Update () {
if(NetworkManager.multiPlayer){
if(Network.isServer){
randomSeed = Random.Range(33, 6574839);
//change here
//if SetSeed void is static
script1.SetSeed(100);
//if SetSeed void is public
GameObject.Find("name").GetComponent<Script1>().SetSeed(100);
//an other public void calling method
GameObject.Find("name").SendMessage("SetSeed", 100);
//networkView.RPC("SetSeed", RPCMode.All, randomSeed);
canModify = false;
}
}
}
Thanks for your code, but I need to send the variable to another Player, on another computer in $$anonymous$$ultiplayer, not to another GameObject in my Game on my computer; I still didn't test the code, are you sure this is going to work in a $$anonymous$$ultiplayer room with 2 Computers connected with a Network?
i am not sure you can try using these methods. if i found something more about this i'll post here .. :)
Your answer
Follow this Question
Related Questions
Multiplayer - sending a variable from server to client 1 Answer
Network Game - all players respond to same input 0 Answers
Entering multiple variables into a function 1 Answer
Space shooter multiplayer problem 0 Answers
SmartFox Physics? 0 Answers