Yield Causing function not to be called on multitouch script

Hi, I’ve been working on a multitouch swipe script, however i seem to have run into a little snag. It occured when I was going to merge the multitouch with the swipe (both of which worked perfectly on their own). It seems a yield within a while loop I use to track the swipe is causing the entire function it is within to go ignored. This yield wassn’t a problem in the original script however now it suddenly won’t play nice. :stuck_out_tongue:

The loop in question:

while (Input.touchCount > 0){
	var ray = mainCamera.ScreenPointToRay(touch.position);
	var thepoint:Vector3 =ray.GetPoint(distance);
	springJoint.transform.position = thepoint;
	yield;
}

This is contained within a function that is called on each update. The touch position is dependent on a touch manager script (however i have checked that it is indeed recieving coordinates, etc.).

Here’s both the update and the DragObject function which contains the loop:

function Update(touch:Touch){

    this.touch = touch;
	isUpdate = true;
		
	
	/*if(!isSelect)
	{*/
		// We need to actually hit an object
		var hit : RaycastHit;
		if (!Physics.Raycast(mainCamera.ScreenPointToRay(touch.position),  hit, 100)) {
			isSelect = false;
			return;
		}
		// We need to hit a rigidbody that is not kinematic
		if (!hit.rigidbody || hit.rigidbody.isKinematic) {
			isSelect = false;
			return;
		}
			
		if (!springJoint)
		{
			var go = new GameObject("Rigidbody dragger");
			var body : Rigidbody = go.AddComponent ("Rigidbody") as Rigidbody;
			springJoint = go.AddComponent ("SpringJoint");
			body.isKinematic = true;
			isSelect = true;
		}
		else 
		{isSelect = true;}
			
		
			
		springJoint.transform.position = hit.point;
			
		springJoint.spring = spring;
		springJoint.damper = damper;
		springJoint.maxDistance = distance;
		springJoint.connectedBody = hit.rigidbody;
			
		
		DragObject(hit.distance, hit.point, touch);
		//}
		
			
}
function DragObject(distance : float, hitpoint : Vector3, touch : Touch)
{   
			   
	var startTime = Time.time;
	var oldDrag = springJoint.connectedBody.drag;
	var oldAngularDrag = springJoint.connectedBody.angularDrag;
	springJoint.connectedBody.drag = drag;
	springJoint.connectedBody.angularDrag = angularDrag;
		
	while (Input.touchCount > 0)
	{
		var ray = mainCamera.ScreenPointToRay(touch.position);
		var thepoint:Vector3 =ray.GetPoint(distance);
		springJoint.transform.position = thepoint;
		yield;
	}

		
	if (springJoint.connectedBody)
	{
		springJoint.connectedBody.drag = oldDrag;
		springJoint.connectedBody.angularDrag = oldAngularDrag;
		springJoint.connectedBody = null;
			
			
	}
		
		
}

I have tried using returns instead of the yield but it doesn’t seem to result in the same effect. I hope someone can help me out as it would be much appreciated :slight_smile:

Regards
MB

I managed to solve it, turns out my mistake was in a part i didn’t include here as i thought it wasn’t relevant. Turns out it was due to my class not being derived from monodevelop and hence didn’t work.

So i added:

 class Coroutiner extends MonoBehaviour
    {
    
    }

and called:

coroutineRunner.StartCoroutine(DragObject(hit.distance, hit.point, touch);

and not it works perfectly :smiley:

Problem was that if you make a coroutine within a class in UnityScript it will need a StartCoroutine.