- Home /
Get Component on Instantiated Object
Hi Guys and girls!
I am having an unusual issue. So far the script looks like this.
var ozzy : GameObject;
var portalPlacer : PortalPlacer;
function Start()
{
ozzy = GameObject.Find("Ozzy");
portalPlacer = ozzy.GetComponent(PortalPlacer);
}
Nothing fancy yet, but for some reason it will not get the Script attached to the game object names "Ozzy". Normally I would write GameObject.Find("Ozzy").GetComponent(PortalPlacer); but I was experiencing issues so wrote this way for now.
I have used code like this for ages, but I think this is the first time it's been on an object that is instantiated and is also attached to a child, but anyway.
It finds the Game Object Ozzy, but wont get the script!
Can anyone offer advice?
Thanks in advance!
Didn't really get your point, but you could try debugging it:
var ozzy : GameObject;
var portalPlacer : PortalPlacer = null;
function Start()
{
while (!portalPlacer)
{
ozzy = GameObject.Find("Ozzy");
portalPlacer = ozzy.GetComponent(PortalPlacer);
Debug.Log ("portalPlacer not found");
yield;
}
Debug.Log ("portalPlacer found!!!");
}
Didn't try the code though.
When you select the Ozzy game object and watch the inspector, do you see the script ? could you make a screenshot of your inspector please ?
Answer by Sundar · Nov 28, 2013 at 07:10 PM
Try this
portalPlacer = ozzy.GetComponent<PortalPlacer>();
Your answer
Follow this Question
Related Questions
Disable/Enable Script or Add/Remove? 1 Answer
How to get all scripts attached to a gameojbect? 1 Answer
Instantiate problem 1 Answer
Instantiate A Prefab 1 Answer
way to get all object with a certain component/script attached 3 Answers