- Home /
This question was
closed Oct 23, 2013 at 12:41 AM by
meat5000 for the following reason:
The question is answered, right answer was accepted
How do I pull a script from a collider that my object is in?
I have a car that pulls up to an intersection. And then it is suppose to pull from the intersection collider what radius to turn at to make a proper turn. How do I code to pull that script from the collider?
I think it is along the lines of this but this is as far as I could get
intersectionScript3Way = other.GetComponent(MonoScript).IntersectionScript;
intersectionScript3Way being my variable inside the car script other is the collider with the script on it IntersectionScript is the script im trying to pull.
Comment
Best Answer
Answer by aldonaletto · Oct 21, 2013 at 11:32 PM
It's almost right:
function OnTriggerEnter(other: Collider){
// try to get the IntersectionScript from the trigger:
var interScript: IntersectionScript = other.GetComponent(IntersectionScript);
if (interScript){ // if script found, get the variable you want:
intersectionScript3Way = interScript.theVariableYouWant;
}
}