I am converting the DragRigidbody.js script to C# for learning purposes more than anything else really, and I have ran into a snag. What Does the DragObject yield return? Code (csharp): float oldDrag = springJoint.connectedBody.drag; float oldAngularDrag = springJoint.connectedBody.angularDrag; springJoint.connectedBody.drag=drag; springJoint.connectedBody.angularDrag = angularDrag; Camera mainCamera = Camera.main; while(Input.GetMouseButton(0)) { Ray ray = new Ray(mainCamera.transform.position, mainCamera.transform.forward); springJoint.transform.position = ray.GetPoint(distance); yield return; // not sure what to return and c# doesn't like this very much } if(springJoint.connectedBody) { springJoint.connectedBody.drag = oldDrag; springJoint.connectedBody.angularDrag = oldAngularDrag; springJoint.connectedBody = null; } Any help would be much appreciated Thank You TWest
I don't think it's documented anywhere, or at least I never was able to find documentation. However, in practice it appears that whenever you return something that is not inheriting from YieldInstruction (e.g. Coroutine, WWW or WaitForSeconds), it will just wait for the next frame. So if you want to translate a Unity Script yield; command, you can really return almost anything you like. Personally, I use yield return 1;. EDIT: the C# manual page does give an example (but does not explain anything): http://unity3d.com/support/documentation/ScriptReference/index.Writing_Scripts_in_Csharp.html In fact, the page even forgets to mention that C# coroutines don't work unless you explicitly use StartCoroutine() to start them.
Actually, in that case it's probably best to use yield return new WaitForEndOfFrame(); - otherwise, your C# code ends up being just as meaningless as the UnityScript code. That's the thing I find really beautiful about converting UnityScript-stuff to C#-code: After the conversion, you can read it and immediately know what it means ;-)
The real issue is here what should I set the return value of the function as anything i put it says its not an iterator interface type, Im seeing what i can find now. Ill post if I can find it. Thank You As soon as I posted found it..IEnumerator