S
S
Sputnik Upitera2019-03-19 22:21:01
C++ / C#
Sputnik Upitera, 2019-03-19 22:21:01

How do I attach a prefab to a script in Unity so that all objects on the stage execute the code?

Good day.
The blue color in the screenshot circles the objects that are on the stage (these are two stairs), which, when attached to the script, work, but only separately, since only one GameObject was specified in the script.
public GameObject platform_ladder;
5c913eee7c978356609117.jpeg
When trying to attach to the Script Inspector (highlighted in yellow) Prefab (circled in red) everything stops working. Although the objects on the stage are this prefab.
On this basis, the question arose:
How, without creating +100500 GameObjects, can a prefab be used as a single object? And is it even possible to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DenisNickname0, 2019-03-19
@DenisNickname0

Try to select a script in the project files and set the desired prefab in the inspector of the game object variable. In theory, then it should be used by default.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question