Using C# - how do I access a script attached to a prefab

clone = (Transform)Object.Instantiate(cube, new Vector3(boxArray[i, 1], boxArray[i, 2],-3), Quaternion.identity);

How would I access and change variables for the Instantiated clone object? The prefab has a Box.cs attached and I can’t figure it out.

Also, is there any robust C# support for Unity3D anywhere?

// gameObject.clone.GetComponent(typeof(Box));
// clone.gameObject.GetComponent(typeof(Box)).direction = 1;//.direction = boxArray[i,0];
// variable = clone.GetComponent(typeof(“Box”)).direction;

clone.GetComponent(Box).direction = 0;
GameObject.clone.GetComponent(Box).direction = 0;
GameObject.clone.GetComponent(typeof(Box)).direction = 0;
clone.Box.direction = 0;

some stuff Ive tried. Theres been alot more over the past few hours, but all of its failed just the same

This is kind of tricky with C#

Try this:

(clone.GetComponent(typeof(Box)) as Box).direction = 0;

If you’re going to access quite a few variables you’ll probably want to assign it to a variable first:

Box myBox = clone.GetComponent(typeof(Box)) as Box;

myBox.direction = 0;
myBox.somethingElse = 1;

Hope that helps,
Nathan

Nathan, thank you very very very very much sir =)

You’re very very welcome! My pleasure! :slight_smile: