I have this script that is being attached to my gameObject:
public class Computer : MonoBehaviour
{
public int AccessLevel;
public Text text;
public InputField inp;
system s = new system();
// Start is called before the first frame update
void Start()
{
s.link(name, AccessLevel, text, inp);
}
public void Run()
{
s.Run();
}
}
Here is the ‘system’ script that I’m making an instance of in the script above:
public class system
{
public string Name;
public int AccessLevel;
public Text text;
public InputField input;
public system Connected;
public Dictionary<string, string> memory = new Dictionary<string, string>();
public void link(string n,int al,Text t,InputField i)
{
AccessLevel = al;
text = t;
input = i;
}
public void Run()
{
MasterServer.Receive(this);
}
}
And finally a ‘MasterServer’ script that will execute the code:
public class MasterServer : MonoBehaviour
{
public static void Receive(system sender)
{
Regex r = new Regex("(connect)\\(\\s*(.*?)\\s*\\);|(.*?)?\\.?(#)\\s*(.*?)\\s*#");
MatchCollection matches = r.Matches(sender.input.text);
foreach (Match m in matches)
{
List<string> g = new List<string>();
for (int i = 1; i < m.Groups.Count; i++)
{
if (m.Groups*.Value != "")*
{
g.Add(m.Groups*.Value);*
}
}
//==================================================================================
//Add Commands Here:
if (g[0] == “connect”)
{
sender.Connected = GameObject.Find(g[1]).GetComponent();
}
if (sender.Connected.Name == g[0])
{
if (g[1] == “#”)
{
sender.Connected.Print(g[2]);
}
}
if (g[0] == “#”)
{
sender.Print(g[1]);
}
//==================================================================================
}
}
}
The main problem is this piece of code in the ‘MasterServer’ script:
sender.Connected = GameObject.Find(g[1]).GetComponent();
it gives an error: (GetComponent requires that the requested component ‘system’ derives from MonoBehaviour or Component or is an interface.)
I’m pretty new to unity and can’t seem to wrap my head around what to do to fix this.
==========================================================================
The main idea is I want to make a Central server that houses all of my functions.
then I create a new system for each computer and link the components to it from the computer.
after that when I press a button that is linked to the ‘Run()’ method in the ‘systems’ script it gives the ‘MasterServer’ script the sender and then executes the code from there.