#Then you won t find it in the `Assets`
1 messages · Page 1 of 1 (latest)
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.
Where is that spot?
*where is that script?
The srcipt is part of a prefab, and this is where I try to reference the text
Is that the script asset?
Yes
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.
So is there no way for object inside the scene and outside the scene to communicate/reference each other?
You can reference objects outside the scene from the scene, but not the other way around.
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?
No. That's not how it works. a prefab and it's instance in the scene are 2 separate objects.
So how else can I get around this problem?
start from describing what you're trying to do.
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.
Seems like you have a wrong approach. Your game logic should probably be controlled by a Game Manager or similar script in your scene that among other things should trigger the Game Over sequence.
Tetris pieces don't control the game, so it's not right for them to have anything to do with UI objects.
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.
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.