Hey, I’m trying to make my own RigidBody dragging script (C#) and I thought the following code would work but it gives me “Object reference not set to and instance of an object” errors (lots). Any idea what I’m doing wrong?
public Transform holdPoint;
public bool somethingHeld = false;
public RaycastHit moveableObject;
// Update is called once per frame
void Update () {
RaycastHit hit;
if(Physics.Raycast(transform.position, gameObject.transform.forward, out hit, 2))
{
if(Input.GetKey(KeyCode.Mouse0)){
if(hit.collider.gameObject.tag == "Moveable" && somethingHeld == false){
hit.collider.gameObject.rigidbody.isKinematic = true;
SpringJoint connectedObject = hit.collider.GetComponent<SpringJoint>();
somethingHeld = true;
connectedObject.connectedBody = hit.collider.rigidbody;
}
else{
if(hit.collider.gameObject.tag == "Moveable" && somethingHeld == true){
hit.collider.gameObject.rigidbody.isKinematic = false;
somethingHeld = false;
}
}
if(hit.collider.gameObject.tag == "Moveable"){
}
}
}
}
The errors appear when I try to drag the rigidbody.
Many thanks.