Problem after conversion C# to Java

Hello, I converted the chat script tutorial Marco Polo (Photon). UnityScript From C # to JAVA. For starters, the line
#C :
photonView.RPC("SendChatMessage", target, chatInput);
must be remplaced by
JAVA :
PhotonNetwork.photonView.RPC("SendChatMessage", target, chatInput);

Why ?

Then, I get this error with the following code:

"NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[]"





function OnGUI(){
if (GUILayout.Button("ALL", GUILayout.Height(17)))
        SendChat(PhotonTargets.All);
}

function SendChat(target:PhotonTargets)    {
    PhotonNetwork.photonView.RPC("SendChatMessage", target, chatInput);
    chatInput = "";
}

@RPC
function SendChatMessage(text:String,info:PhotonMessageInfo)    {
    AddMessage("[" + info.sender + "] " + text);
}

static function AddMessage(text:String)    {
    SP.messages.Add(text);
    if (SP.messages.Count > 15) SP.messages.RemoveAt(0);
}

Thank you.

Comments

  • the replacement is not required.
    The only thing you might potentially need is add a @import PhotonNetwork; at the top assuming you had a using PhotonNetwork; before in C# and then get a reference to the PhotonNetworkView on this game object through GetComponent (or extend from PhotonMonoBehaviour)

    the second code for UnityScript there (unity does not support java in any form) does something different than the original code as it has no relationship to the local game object and its view.
  • You need to make sure your script has the @import PhotonNetwork; and you also should move the "plugins" folder to the root of your project. This makes sure the cs-scripts are compiled first and your game scripts (in UnityScript) can access the classes we defined.

    This should do the trick.