- Home /
Access object script from prefab script
Have a prefab with script that interacts with another prefab. Put simply, if they touch I need to update a score variable which resides in a gameobject script. I can not for the life of me figure out how to access it, as I can not reference scripts in the same way you can with two scripts attached to gameobjects.
Answer by tormentoarmagedoom · Oct 09, 2019 at 07:30 AM
Hello.
A prefab, is just a non instanced object. Once you Instantiate it in the scene, it becomes a GameObject like any other, and can bea ccesed as any other. Your question is too ambiguous to reciece a concreete answer...
You can reach any object in the scen by thousanbds of ways! For example, using;
https://docs.unity3d.com/ScriptReference/GameObject.FindGameObjectsWithTag.html
or
https://docs.unity3d.com/ScriptReference/Object.FindObjectOfType.html
or all methods of " collisions familly" like;
https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html
or from its parents
or its childs
and more, more ,more...
FAQ
What kind of questions can I ask here? Unity questions, of course! As long as your question is:
detailed and specific written clearly and simply of interest to at least one other Unity user somewhere ... it is welcome here. Oh yes, and it should be about Unity.
Please look around to see if your question has already been asked (and maybe even answered!) before you ask. If you end up asking a question that has been asked before, it may end up getting rejected in the moderation queue or closed if it has been published. Other users will hopefully edit in links to related or similar questions to help future visitors find their way.
Your answer
![](https://koobas.hobune.stream/wayback/20220612213200im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Export game objects with mesh paths 0 Answers
Change script from EditorWindow 0 Answers
How to detect if Prefab was added to the scene in Edit Mode? 1 Answer
How to run script in editor 1 Answer
My prefab isn't getting destroyed 1 Answer