- Home /
Question by
SlothJesus · Dec 10, 2013 at 03:57 PM ·
c#getcomponent
GetComponent not working C#
void OnJoinedRoom()
{
GameObject worker = PhotonNetwork.Instantiate("Worker",new Vector3(50,5,50) ,Quaternion.identity,0);
Seeker seeker = worker.GetComponent<Seeker>();
seeker.enabled = true;
pathfindingAIScript aiScript = worker.GetComponent<pathfindingAIScript>();
aiScript.enabled = true;
}
I am trying to use Photon Cloud, and for some reason GetComponent is not working. The worker prefab is instantiated, but then I get the error "Object reference not set to an instance of an object". I go to check the inspector of the worker instance and neither seeker or pathfindingAIScript are added.
Comment
Answer by applejuices · Dec 10, 2013 at 04:12 PM
er try.... public Component Seeker;
seeker = gameObject.find("WOrker").GetComponent("Seeker");
HAvent tested it, might not work well but it works mostly for me
Your answer
![](https://koobas.hobune.stream/wayback/20220613123849im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Error when using getComponent to use a variable 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
does not implement right interface 1 Answer