Updating a variable on a script in an instanced object

I'm still trying to grok Unity's naming system - I apparently still can't figure out how to update the variable on a script inside an instanced object (prefab)!

Prefab `Ford` has script `CarsInternal.js`, which has an exposed variable `var cars:int;` - There can be N instances of Ford, as Ford is a prefab.

A single script, `External.js` in a single object `Brands` is trying to update the `cars` integer in Ford. How do you update that variable from `External.js`?

See the second example from the scripting reference (linked below). Basically, create an array of all instantiated prefabs (by tag) and loop through them. Instead of what they do in the reference page, just reference the said script like:

var CarsInternalScript: CarsInternal = go.GetComponent('CarsInternal') as CarsInternal;

and access it like:

CarsInternalScript.cars = 1337;





If you mean changing the variable of a prefab before you instantiate it, check this manual page (and especially the Instantiating rockets & explosions and Replacing a character with a ragdoll or wreck part):


Hope this helped.