- Home /
Get child name from another parent
I'm doing a Hearthstone style game. Is there any way to get the gameobject's name from another parent where my card is positioned at the end of the drag?
It is probably possible to do what you want but I do not quite understand what you want to achieve / mean. Another parent? Parent of what? Do you want to know what game object your card is positioned over? Do you have any code / sketches / images to clarify what you want help with? Generally you can use OnTriggerEnter to see what your object collides with (https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html) and from the collider get the game object your colliding with and its parents / children whatever it is you need. But perhaps with some more details it becomes easier to help you do what you want.
If you have collision box and trigger on the parents of the cards you could do something like this if you have this code on parent/ card A and want to drag it onto parent of card B (and you have named it cardBParent) and find it's name private void OnTriggerEnter(Collider other) { if(other.gameObject.name="cardBParent") {
foreach (Transform currChild in other.gameObject.transform) { Debug.Log ("Child found. Name: " + currChild.name); } }
Didn't work. I'm not using collision boxes, i'm with draggable and dropzone. I tryed to add box colliders, but I didn't understand really well how they work.
Damn, my $$anonymous$$d reading skills are a bit rusy. ;)
If you show the code, information about what object you have it on as well an image of your editor with the hirarchy it would be easier for me to explain what you need to do to get what you want from what you have.
Answer by erlantzlor · Apr 28, 2020 at 06:59 PM
I have 2 cards, each one inside a diferent parent. I want to drag A card to the B, which is in a different parent, and show on the debug the name of the B card. Sorry if I expressed bad the first time.
Your answer
Follow this Question
Related Questions
Trading card game uniqe id generation 2 Answers
setactive true in OnBeginDrag 1 Answer
trading card game question with board element 0 Answers
A little hand with a Card Game 0 Answers
Playing Cards With Special Shrinking & Twisting Effects 1 Answer