- Home /
How to get script from Object with (Clone)'s script?
I have a really difficult Problem:
I have a Prefab which I use multible times in the scene.
In the Prefab script I have to use a script from a GameObject.
Here you can see it: The DroppedItem(Clone) have to use the script from the inventory.
I tried a lot and google didn't help me... I hope someone here can help me, thanks!
Answer by malkere · Jul 03, 2015 at 02:07 PM
I use several static manager classes that are not on objects, just persistent throughout the game world at all times. The main one of these always finds player when the game starts and assigns him/her as a static player variable on the static manager script, as well as the mainUI, etc. This way anything that wants to can call managerScript.mainUI.GetComponant().----- or whatever.
alternatively you can just use GameObject.Find("Inventory").GetComponant().----
Is that what you mean? How to get to the script on the object?
Answer by Kolodej · Jul 03, 2015 at 02:12 PM
There is a more options:
Hold the reference to the Inventory GO in "dropped items"
use
GameObject.Find("Inventory").GetComponent();
The inventory can be implemented as a singleton pattern Inventory.Instance.DoSometgong(DroppedOpject)...
Just choose what you want, depends