- Home /
 
               Question by 
               fpdotmonkey · Jun 27, 2017 at 01:52 PM · 
                gameobjectjointchild objectparent-child  
              
 
              Modifying HingJoint2D in a child GameObject
I have a prefab built with this structure:
 Parent GameObject
 - Child1 GameObject
     - Rigidbody2D
     - HingeJoint2D
 - Child2 GameObject
     - Rigidbody2D
I would like to increase the velocity of the motor on the HingeJoint2Dwhen I hold click on the prefab. I have the following code code attached to Parent to do this, but I am getting an error saying that I have no HingeJoint2D attached to Parent. How then do I access the HingeJoint2D in Child1?
 public class SpinUp : MonoBehaviour {
     void Start() {
         hinge = GetComponent<HingeJoint2D>();
         motor = hinge.motor;
     }
     void OnMouseDrag() {
         accelerateMotor();
     }
     private void accelerateMotor() { /* whatever */ }
 }
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                