class issues with interacting with unity gameobjects (using c# server )
Hey guys got a major issue here. i wrote my own class to handle network communication and i'm running into some issues integrating it with unity
this code works. but its not my desirable outcome.
Debug.Log("Componenet name: " + GameObject.Find("NetworkManager").GetComponent<InstantiateList>().instance[0].name);
GameObject msg = (GameObject)Instantiate(GameObject.Find("NetworkManager").GetComponent<InstantiateList>().instance[0], Vector3.zero, Quaternion.identity);
msg.GetComponent<Text>().text = message;
msg.transform.SetParent(GameObject.Find("ChatTxtContent").transform);
Debug.Log("My object Reference: " + myGameObject.name);
this code does not work and it is my desirable outcome
/ Debug.Log("Start Receive Message"); GameObject msg = (GameObject)Instantiate(myGameObject.GetComponent().instance[0], Vector3.zero, Quaternion.identity); msg.GetComponent().text = message; msg.transform.SetParent(GameObject.Find("ChatTxtContent").transform); Debug.Log("End Receive Message"); /
the issue is this. i have a class called Command and it runs my RPC methods for me. but some of those methods need to interact with gameobjects in the game etc chat messages with instantiating text and adding it to the contentView of a ScrollList.
some methods are static and some are standard void that take some params* the code that does not run will only run up until the first Debug.Log("Start Receive Message"); then ignoring the rest of the method. i have referenced the object on connect method at the start passing in this.gameobject storing it in the class as a public GameObject. and i ahve used that to reference, i had tested that it is referenced properly by doing a debuglog of the gameobjects name and it worked. however when i try and use this reference to communicate it does not.
i had made a new instance of the class above in my main script that i am using to communicate with the Command Class as so private Command cmd = new Command();
however nothing i want to access in the game will work unless i use GameObject,Find("ObjectsName") then do my business.
some light on this matter would be much appreciated.
thank you very much for your time in reading this.
Your answer
Follow this Question
Related Questions
Can not access GetComponentInParent ( ). usegravity 1 Answer
Error CS1519 1 Answer
Animation won't stop (Solved) 2 Answers
The referenced script on the behaviour is missing error help plz 2 Answers
GameObject not looking at me.. 1 Answer