Reputation: 27
Im new in unity and I have a problem regarding arrays.
I want to be able to set the Elements of the arrays via script. Here straight is a "public gridElementScript[] straight;"
Upvotes: 0
Views: 72
Reputation: 2383
If I'm understanding correctly, you're asking how to access Straight
from another instance. If so, you need to cast your instantiated prefab to a GameObject
and call GetComponent<MyComponent>()
on it. Something like I've written below should work for you.
GameObject object = (GameObject)Object.Instantiate(myPrefab)
GridElementScript script = object.GetComponent<GridElementScript>();
script.Straight[0] = neighbor
Upvotes: 1