Witam,mam pewien problem, otóż napisałem prosty czat do mojej gry i chciałem umożliwić również wykonywanie prostych komend administratorskich takich jak czyszczenie ekwipunku i przydzielanie przedmiotów. Z metody windowFunc wywołuję metodę ClearInventory:
public static void ClearInventory()
{
for (int i = 0; i < inventory.Count; i++)
{
inventory [i] = new Item ();
}
}
[RPC]
private void windowFunc(int id)
{
GUI.BeginGroup (windowRect);
ScrollPosition = GUILayout.BeginScrollView (ScrollPosition,GUILayout.Width(75),GUILayout.Height (350));
GUILayout.Box(messBox, GUILayout.Height(350));
GUILayout.BeginHorizontal();
messageToSend = GUILayout.TextField(messageToSend);
GUILayout.EndScrollView ();
GUI.EndGroup ();
if (GUILayout.Button("Send" , GUILayout.Width(75)))
{
if(user != "") //Nick
{
if(messageToSend.Contains("//"))
{
// Tutaj tworzymy Komendy
if(messageToSend == "//test")
{
networkView.RPC("SendMsg", RPCMode.All,"<color=#00a2ff>" + "Wszystko OK" + "</color>" + "\n");
messageToSend = "";
}
else if(messageToSend == "//clear")
{
Inventory.ClearInventory();
}
else
{
networkView.RPC("SendMsg", RPCMode.All,"<color=#00a2ff>" + "Jan nie mógł znaleźć tej komendy!" + "</color>" + "\n");
messageToSend = "";
}
}
else
{
networkView.RPC("SendMsg", RPCMode.All, user + ": " + "<color=#00a2ff>" + messageToSend + "</color>" + "\n");
messageToSend = "";
}
}
else
{
}
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Gracz:");
user = GUILayout.TextField(user);
GUILayout.EndHorizontal();
GUI.DragWindow(new Rect(0, 0, Screen.width, Screen.height));
}
Gdy próbuję uruchomić grę to otrzymuję błąd:
Assets/Scripts/ChatSystem/Chat.cs(54,59): error CS0120: An object reference is required to access non-static member `Inventory.ClearInventory()'
dodanie znacznika <code class="none">
- @furious programming