- Home /
GameObjects escaping somewhere and losing its collider when touch and drag in iOS
Hi all,
Am trying to touch and drag my game object to some places in screen. Some times the game object is escaping some where that means out of bounding boxes and its losing its collider. i dont know why its happening ? if any one face this same problem previously kindly provide me suggestions. and here is my code for touch and drag....
Code :
Touch touch = Input.GetTouch(0); Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position); RaycastHit hit; if (collider.Raycast (ray, out hit, 100)) { if(hit.collider.gameObject.name == "box") {
if (touch.phase == TouchPhase.Began) {
screenPoint = Camera.main.WorldToScreenPoint(transform.position);
offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, 0));
} else if(touch.phase == TouchPhase.Moved) {
Vector3 currentScreenPos = new Vector3(touch.position.x, touch.position.y, 0);
Vector3 currentPos = Camera.main.ScreenToWorldPoint(currentScreenPos)
+ offset;
transform.position = currentPos; } } }
Thanks in advance.
Comment
Your answer
Follow this Question
Related Questions
Logic to detect objects entering between the player and camera? 1 Answer
How to perform intersection test between two colliders? 2 Answers
Moving Colliders giving me Physics.simulate spikes in Profiler 2 Answers
Mesh collider performance ios 2 Answers
iOS (iPad1) CRASH caused by Mesh.Bake PHYSX CollisionData 2 Answers