V
V
Vlad-12345678902022-03-21 09:13:54
C++ / C#
Vlad-1234567890, 2022-03-21 09:13:54

How to get a link to the Inventory (located on the player's prefab) from the InventoryGUI (hanging on the stage in the UI panel in the Canvas)?

Inventory hangs on the player's prefab, and InventoryGUI hangs on the stage, in the canvas. How can I get a reference to Inventroy from InvantoryGUI or vice versa? It only came to my mind to make a prefab out of canvas and spawn it from Inventory, is there another way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nekit Medvedev, 2022-03-21
@Vlad-1234567890

Access to a static class (or singleton) can be obtained from anywhere in the application, you can create an adapter class in which you will write the information you need and from which you will receive it. By the way, a static class and a loner are not the same thing. Static classes are advised not to be abused, I did not use them in the unit, so see for yourself.
Search for an object by ID or tag and create a link to it.
This is if you want to do it programmatically, in the inspector you can simply drag the object with the desired component to the required field, if the class names match, then the unit will do everything.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question