I’m attempting to use the script found here (How to drag gameobject with mouse - Questions & Answers - Unity Discussions) to drag objects around. I’m converting it to C#, however and I’m not sure what I need to do to get the yield statement to play nicely. Here’s my current code:
void OnMouseDown() {
Vector3 screenSpace = Camera.main.WorldToScreenPoint(transform.position);
Vector3 offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z));
while (Input.GetMouseButton(0)) {
Vector3 curScreenSpace = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenSpace) + offset;
transform.position = curPosition;
//YIELD GOES HERE - How do I do this in C#?
}
}
Any ideas? Not using a yield results in crashing Unity. Thanks in advance for your help!