- Home /
Changing a variable in another script over the network
Hello,
I am trying to find out how to find out how to change a variable in an object I just instantiated over the network using an RPC call. However, the variable damage and gameObject name only change locally and not over the network. This object and the object I'm trying to reach have a networkView. Any help is appreciated.
[RPC]
public void DealMapWideDamage(float amount)
{
mapWideAOEClone = Network.Instantiate(Resources.Load("MapWideAOE"), new Vector3(0,0,0),Quaternion.identity,0) as GameObject;
//Need to find out a way to give MapWideAOE the variable damage
mapWideAOEClone.name = "Damage";
Damage_Script damage_Script = mapWideAOEClone.GetComponent<Damage_Script>(); //Get damage script and deal some damage
damage_Script.damage = amount; //etc.
}
void Update() //Using update to show how I'm declaring the rpc call
{
networkView.RPC("DealMapWideDamage",RPCMode.All,damage);
}
Answer by jpthek9 · Jan 17, 2015 at 12:04 AM
There aren't any errors in the code as far as I can tell. Note that when you use networkView.RPC, you're calling the RPC on that networkView on all clients. So if you want to tell the enemy you hit to take damage, you would call that enemy's networkView instead of your own.
Are there any errors popping up or are debug.logs simply not showing up?
Sorry about that, I updated the code to show how I'm doing the RPC call.
No errors appear, it just seems that I can't access and modify these variables over the network.
I'm sorry but there's nothing wrong with what you're showing.
Ok thank you for the help, I'll see if there is an error on my part Anywhere in my scripts.
jpthek9 is correct. After reviewing the output logs it does print the information I want it to. The name of the object changes on all, but as for getting the variable over the network... make it simpler on yourself by not getting the component but by using another method as from my experience with it, it could cause some trouble.