#Then you won t find it in the `Assets`

1 messages · Page 1 of 1 (latest)

brazen grove
#

I can see it in the Hierarchy. But I am unable to drag it into the spot where I would reference in in the Script.

digital raven
#

*where is that script?

brazen grove
#

The srcipt is part of a prefab, and this is where I try to reference the text

digital raven
brazen grove
#

Yes

digital raven
#

Ok, first of all, you don't assign things in the script asset, unless you know what it is for.

#

You assign them on the component instance.

#

second, you can't reference things in the scene from outside the scene.

brazen grove
digital raven
#

You can reference objects outside the scene from the scene, but not the other way around.

brazen grove
#

If I made the text into a prefab, then it would be both inside and outside of the scene. Would I be able to then reference it form a prefab that is not in the scene?

digital raven
brazen grove
#

So how else can I get around this problem?

digital raven
#

start from describing what you're trying to do.

brazen grove
#

I am trying to recreate Tetris. The pieces are prefabs, which have a Script element that includes tracking the board in a 2d array. Inside that script is where I am trying to trigger the Game over screen when the top of the grid contains an object.

digital raven
#

Tetris pieces don't control the game, so it's not right for them to have anything to do with UI objects.

brazen grove
#

Even if I did that, I would have to somehow communicate what pieces get placed where in the grid, so the same problem of referencing objects in scene with ones that are not always on scene.

digital raven
#

As I said, you can reference prefabs from the scene. Not the other way around.
For things you instantiate at runtime, you should have references to the new objects.
In very rare cases, it's ok to use one of the Find functions to get the reference at runtime.

#

Also, your parts don't need to communicate with the Game Manager. The GameManager does need to interact with the parts, but it should naturally have access to them if it's spawning them.