Home > Back-end >  Increase size of touch area - Unity
Increase size of touch area - Unity

Time:11-16

private void onm ouseDown()
    {
        screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
        offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));        
    }

With this code I can touch the point on the screen but when I catch my balls on the screen sometimes i can't because they are too fast.

So can i take the point of click and enlarge this point ?

CodePudding user response:

You can use a 2D or 3D Sphere collider and attach it to Empty gameobject , move that game object towards touch points on screen and use OnCollisionEnter2D() or OnCollisionEnter3D() event to detect detections with falling balls. Now the sphere collider is as a whole a point and its radius can altered in inspector to enlarge the points

More about On Collision Event : https://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html

  • Related