using UnityEngine;
using System.Collections;

public class Ropify : MonoBehaviour {

	public float spring;
	public float damper;
	public float segmentDrag;

	void Start()
	{
		for (int i=0; i<transform.childCount; i++) {
			Transform splineSegment = transform.GetChild(i);
			Rigidbody rb = splineSegment.gameObject.AddComponent<Rigidbody>();
			rb.useGravity = false;
			rb.drag = segmentDrag;
		}

		for(int i=0; i<transform.childCount-1; i++)
		{
			Transform child = transform.GetChild(i);
			Transform nextChild = transform.GetChild (i+1);
			SpringJoint joint = child.gameObject.AddComponent<SpringJoint>();
			joint.connectedBody = nextChild.rigidbody;
			joint.spring = spring;
			joint.damper = damper;
			joint.minDistance = 0f;
			joint.maxDistance = 0.1f;
		}
	}
}
