Question by 
               PultroN93 · Sep 22, 2018 at 01:43 PM · 
                gameobjectraycastgetcomponentraycasthitchildren  
              
 
              Get component from parent of children hittet with raycast
I have many chests placed on terrain from prefab. Every chest has animatior with animations. I want to get Animator component from chest which is hitted by raycast.
 if (Physics.Raycast(ray, out rayCastHit, 5))
         {
             if (rayCastHit.collider.tag == "chest")
             {
                  Animator... //how to get component?
             }
 
               The "chest" tag is children of object where the animator component is. How to get component from parent of children hittet with raycast?
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by PultroN93 · Oct 01, 2018 at 06:59 PM
Ok, did it:
 if (rayCastHit.collider.tag == "chest")
              {
                    Animator = hit.collider.gameObject.GetComponentInParent<Animator>();
              }
 
              Your answer
 
             Follow this Question
Related Questions
How to freeze an GameObject on x axis in specific direction? 1 Answer
ChildsParentObject Function 0 Answers
How would I project a Gameobject onto the surface of another? 0 Answers
Raycast shooting, child collider call and detection 0 Answers
this.GetComponent() won't return gameObject? How to get it without using this.gameObject? 3 Answers