- Home /
The question is answered, right answer was accepted
mobile touch ios doesn't work anymore after update to 5.3.4
I was making a game when I updated unity the drag script didn't work any more I don't get any errors please help this is my script:
using UnityEngine; using System.Collections; public class Dragger: MonoBehaviour { public int maxTouch = 2; [Range(0,31)] public int layerMask = 0; public float distance = 0.2f; public float dampingRatio = 1; public float frequency = 1.8f; %|-1782931336_7|% public float angularDrag = 5.0f; public bool centerOfMass = false; private SpringJoint2D[] springJoints; void Start () { springJoints = new SpringJoint2D[maxTouch]; for (int i = 0; i < maxTouch; i++) { GameObject go = new GameObject ("Dragger" + (i + 1)); go.transform.parent = this.transform; Rigidbody2D body = go.AddComponent <Rigidbody2D>() as Rigidbody2D; springJoints [i] = go.AddComponent <SpringJoint2D>() as SpringJoint2D; %|1623580026_19|% } } void Update () { foreach (Touch touch in Input.touches) { int Id = touch.fingerId; if (Id < maxTouch && touch.phase == TouchPhase.Began) { Camera mainCamera = FindCamera (); Ray ray = mainCamera.ScreenPointToRay (touch.position); RaycastHit2D hit = Physics2D.GetRayIntersection (ray, Mathf.Infinity, 1 << layerMask); if (hit.rigidbody != null && hit.rigidbody.isKinematic == false) { springJoints [Id].transform.position = hit.point; %|-307089627_32|% %|898935706_32|% springJoints [Id].connectedAnchor = hit.rigidbody.centerOfMass; else springJoints [Id].connectedAnchor = hit.transform.InverseTransformPoint (hit.point); float length = (hit.transform.position - mainCamera.transform.position).magnitude; StartCoroutine (DragObject (Id, length)); } } } } IEnumerator DragObject (int Id, float length) { float oldDrag = springJoints [Id].connectedBody.drag; float oldAngularDrag = springJoints [Id].connectedBody.angularDrag; springJoints [Id].distance = distance; %|-411076151_49|% springJoints [Id].frequency = frequency; springJoints [Id].connectedBody.drag = linearDrag; springJoints [Id].connectedBody.angularDrag = angularDrag; Camera mainCamera = FindCamera (); while (true) { bool touchExists = false; foreach (Touch touch in Input.touches) { if (touch.fingerId == Id) { touchExists = true; Ray ray = mainCamera.ScreenPointToRay (touch.position); springJoints [Id].transform.position = ray.GetPoint (length); } %|-1491490236_62|% %|-554512503_63|% yield return null; else break; } %|-590301434_68|% %|-1983571684_64|% springJoints [Id].connectedBody.angularDrag = oldAngularDrag; springJoints [Id].connectedBody = null; } } Camera FindCamera () { if (GetComponent<Camera>()) return GetComponent<Camera>(); %|-14636753_79|% return Camera.main; } }
Answer by Sortof · Apr 20, 2016 at 12:29 PM
I had a similar issue, and fixed it by disabling "Auto Configure Distance" for the joints.
springJoints[i].autoConfigureDistance = false;
Follow this Question
Related Questions
Updating minor versions 2018.2.0 to 2018.2.1 and Unity Hub 0 Answers
Upgrading unity. Files kept? 1 Answer
Camer angle of rift shifts on start 0 Answers
Text Not updating 1 Answer
auto change script in published build 0 Answers