i try to develop a new multiplayer game in unity and i have a problem to make work The RPC function. and i get the error Assets/RPC.js(25,2): BCE0033: The type ‘RPC’ is not a valid attribute. were this line is the @RPC Its seams i missing something

this is my code

var cube : GameObject;
var nView: NetworkView;
function Start() {
nView = GetComponent.<NetworkView>();
}
 function Update () {

}



function OnGUI(){
if (GUI.Button(Rect(100,200,100,40), "Make a Cube")) {

    var viewID : NetworkViewID= Network.AllocateViewID();

    nView.RPC("MakeCube", 
                    RPCMode.AllBuffered, 
                    viewID, 
                    transform.position);
}

}

@RPC
function MakeCube(){
Instantiate(cube, transform.position, transform.rotation);
}

Which ancient Unity version are you actually using? UnityScript as well as the very old network engine RakNet has been deprecated ages ago.

Anyways there are several things wrong here. First of all you allocate a new ViewID but you haven’t assigned it to any NetworkView component. That doesn’t make much sense. Next thing is you pass two parameters to your RPC method but your method doesn’t have any parameters. So either do something with the parameters or remove them from the call.

When you want to instantiate objects in a network environment you usually use Network.Instantiate. Make sure the prefab you try to instantiate has a NetworkView component attached.

Finally your biggest error which actually causes the error you’re seeing: You named your script file “RPC.js”. That means you created your own class named RPC. This hides Unity’s RPC attribute class. You have to rename your class / script file to something that actually describes what this script does.