- Home /
An odd GetComponent error...
I am getting a 'waypoint is not a member of 'UnityEngine.Component' error. And I don't know what is wrong...
CODE WAS HERE.
By the way, I did set up another script called waypoinSoldier and variable waypoint(if you were wondering)
Please tell me what I am doing wrong. Thanks.
EDIT:
CODE WAS HERE.
Answer by Mike 3 · Jul 25, 2010 at 01:24 AM
If you're on the iPhone, it's because it doesn't support dynamic typing, so you have to force the type manually
Alternatively, you could have #pragma strict at the top of your file if you're not on iPhone - it does the exact same thing
var soldier : waypointSoldier = instantiated.GetComponent(waypointSoldier);
soldier.waypoint = hit1.collider;
Note: You should get into the habit of doing that anyway, it's quite a bit slower to do it the way you're trying
Edit:
change
var instantiated : Rigidbody = Instantiate (unit, transform.position, transform.rotation);
to
var instantiated : waypointSoldier = Instantiate (unit, transform.position, transform.rotation);
That'll be why it wasnt working with transform either (though using the script type is much better)
Can't see anything wrong at first glance, only thing i can think of is that the script isn't on the root object or something along those lines. is it throwing any runtime errors? Other than that, no clue, try debugging what's null and what isn't
Probably that the script isn't on the root of the object. try GetComponentInChildren ins$$anonymous$$d
if it were me, i'd change the type for unit to be waypointSoldier (which will mean readding the prefab). Then you don't even need to do getcomponent, it'll be the right object type, and you know for sure your object has the script on
var unit : Transform; becomes var unit : soldierWaypoint; - after which you $$anonymous$$UST reselect the prefab in the inspector
Your answer
Follow this Question
Related Questions
Player Prefs, Adding Two Variables 1 Answer
C# GetComponent()... Not finding script problem. 1 Answer
Instantiate Prefabs. Errors. 2 Answers
error CS1525: Unexpected symbol `)' 1 Answer