Answer the question
In order to leave comments, you need to log in
How to connect a class without an object on the stage?
I have a Server class, it has a SendData method, there is a Menu class, it has a Click1 method, how can I call the SendData method of the Server class in the Click1 method, given that the Server class is not hung on anything, and the Menu class is hung on the button which the Click1 method is called when clicked.
public class Server : MonoBehaviour{
public static void SendData(){
StartCoroutine(SendDataWWW());
}
IEnumerator SendDataWWW(){
..........
}
}
public class Menu : MonoBehaviour{
GameObject obj;
Server srv = obj.GetComponent<Server>();
public void Click1(){
srv.SendData();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question