- Home /
The question is answered, right answer was accepted
Why is this GetComponent not working?
Its not getting the script here called ds on entering the trigger area. It detects the collider that hits it though I checked.
What it does is act as a trigger for an area of sand which your player passes over. Once within the area it is supposed to instantiate the particles at the transforms set in the vehicle.
So yeah whats going on?
Code:
public ParticleEmitter groundTrailParticle;
}
void OnTriggerEnter(Collider other){
if(other.tag == "car"){
groundTrailParticle.enabled = true;
//The problem starts here.
CarController ds = other.GetComponent<CarController>();
for(int i = 0; i < ds.wFx.Length; i++){
Instantiate(groundTrailParticle, ds.wFx[i].position, ds.wFx[i].rotation);
}
}
You have already initialized the variable ds, so there's no need to denote the type CarController on line 16. $$anonymous$$aybe that's messing things up? Also, it seems like the type you set when you initialize it is different than the type you set on line 16. That could also be a problem.
Oh crap I made error in posting. ds is not supposed to be intitialized beforehand that was supposed to be edited out.
That is not the problem.
It runs and throws up reference not set error at line 16 when I enter the trigger.
I've never seen the syntax you use on line 15 with the CarController before the parentheses. That might just be because I am very inexperienced, but it could be worth a try to write it as other.GetComponent(CarController) ins$$anonymous$$d.
Answer by DeadKenny · Dec 09, 2013 at 12:33 AM
AH ok lol I found it. The component is in the Parent of the Object with collider in car.
CarController ds = other.transform.parent.GetComponent<CarController>();
FIXED!!! Thanks though man.
Follow this Question
Related Questions
Order of object instantiation scripting issues 0 Answers
Getting a component of an instantiated object returns an error 1 Answer
How do I re-instantiate original prefab after a game object inside has been destroyed? 2 Answers
Accessing Variable From Other Gameobject 1 Answer
Only 1 of 3 conditions being executed in IF statement?(Solved) 1 Answer