- Home /
Get a parent GameObject from a class on a script attached to a prefab,Getting a parent Gameobject from a component on a script attached to a prefab
Designing a card game, here's the thinking: Have a Player Object > Hand Object > Individual Card Objects Card.cs is attached to a prefab; in Card, there is a CardComponent class which is a scriptable class that provides the actual functionality of the card. My basic card is "Deal 1 Damage", which can be dodged by the player or enemy. Thus, I want to be able to select targets back-and-forth. I want to reference the parent game object (aka Player Object), from the CardComponent which is used by Card.cs. Please advise.,Designing a card game here: the thinking is to have a Player object> Hand Object > Individual Cards A Card is a ScriptableObject have a single CardComponent (separate class). I want my separate CardComponent to be able to identify the parent game object (meaning the Player object) because it is an interaction-based game. For example, the player plays an Attack card, and the enemy can play a dodge card, and vice versa, thus needing a interchanging target selection mechanism. I wanted the CardComponent to identify its origin/parent GameObject and then the user can choose the target GameObject. Please advise.
Answer by Arpi01 · Jul 25, 2019 at 11:38 PM
I think this is what you want https://docs.unity3d.com/ScriptReference/Transform-parent.html
Your answer
![](https://koobas.hobune.stream/wayback/20220612205448im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Instantiate with random scriptableObject 2 Answers
How to reference a scene gameobject from a custom project asset? 2 Answers
Build does behave different to editor 2 Answers
Need some advice for my inventory system 0 Answers