- Home /
How do I address the protection level to allow my C# script to communicate with my Java script?
I get the error "Assets/Scripts/CursorControl.cs(46,32): error CS0122: `MultiplayerScript.showDisconnectWindow' is inaccessible due to its protection level" for the following code, namely line 46 where I'm trying to lock the cursor and pull up a "disconnect from server" window. However I don't seem to have the permission? Is this a multiscript issue or am I missing something?:
using UnityEngine;
using System.Collections;
/// <summary>
/// This script is attached to the player and it controls
/// whether the cursor is locked or unlocked.
///
/// This script accesses the Multiplayer script.
/// </summary>
public class CursorControl : MonoBehaviour {
//Variables Start___________________________________
private GameObject multiplayerManager;
private MultiplayerScript multiScript;
//Variables End_____________________________________
// Use this for initialization
void Start ()
{
if(networkView.isMine == true)
{
multiplayerManager = GameObject.Find("MultiplayerManager");
multiScript = multiplayerManager.GetComponent<MultiplayerScript>();
}
else
{
enabled = false;
}
}
// Update is called once per frame
void Update ()
{
if(multiScript.showDisconnectWindow == false)
{
Screen.lockCursor = true;
}
if(multiScript.showDisconnectWindow == true)
{
Screen.lockCursor = false;
}
}
}
The script is meant to be attached to the player, but threw up error "Not finished compiling, please wait for script to compile and try again." However, I deleted the component and put the script in manually with a new component, and the console gave me this:
CheckConsistency: GameObject does not reference component $$anonymous$$onoBehaviour. Fixing. UnityEditor.DockArea:OnGUI()
Thanks Linus, that removed the error and I'm back to work! So when you're using multiscript you have to use public variables even if the class itself is public?
Converted my comment to answer.
Yes when communicating between scripts (each script is actually a class), variables and functions you want to access needs to be public.
Answer by Linus · Mar 03, 2014 at 12:24 AM
Make sure multiScript.showDisconnectWindow (the variable showDisconnectWindow inside MultiplayerScript.cs ) is public and not private.
Your answer
![](https://koobas.hobune.stream/wayback/20220613135223im_/https://answers.unity.com/themes/thub/images/avi.jpg)