- Home /
Question by
GregoryNeal · Apr 29, 2015 at 06:43 PM ·
missing script
Missing a using directive or an assembly reference
Hey guys I'm trying to add this component to a GameObject, the script Ground is in my project pane but it's still giving me the above error.
private void SpawnAtPosition(Ground groundScript, string dir, bool isNew)
{
GameObject ground;
if(isNew)
{
Ground go = GetFurthestInX(dir,false);
float xPos = go.getLocationX;
float yPos = -go.gameObject.GetComponent<SpriteRenderer>().bounds.extents.y;
if(dir == forward)
{
xPos += go.gameObject.GetComponent<SpriteRenderer>().bounds.extents.x;
//ground = Instantiate(
}
if(dir == backward)
{
xPos -= go.gameObject.GetComponent<SpriteRenderer>().bounds.extents.x;
}
}
else
{
ground = Instantiate(Resources.Load(groundScript.path),groundScript.Location,Quaternion.identity) as GameObject;
ground.AddComponent<groundScript>();
if(dir == forward)
{
prevSpawnedForward = groundScript;
}
if(dir == backward)
{
prevSpawnedBackward = groundScript;
}
}
}
And here is my project pane:
capture.jpg
(34.4 kB)
Comment
which line is the error on? What is the error exactly?
Skim$$anonymous$$g through, shouldn't ground.AddComponent( groundScript ) be ground.AddComponent( Ground ) ?
Exactly what I was going to say.
You cannot use AddComponent<variable>() you need to use AddComponent<Class>()
And then you could assign values to the variables of the newly added component.
Oh okay, I guess I wasn't clear enough. The point of the rest of the code (that I didn't copy/paste) is to build a Ground object with its setter methods and I thought I could just add this instance of the class as a component. I was wrong. Thanks guys I understand my mistake.