hi, im making a code setting if i touch a collider it do something
i was using a code with 2D but now i need it to be in 3D
my code when im using in 2D is
if (Input.touchCount == 1) {
Touch touch = Input.GetTouch(0);
if (Input.touchCount == 1 && touch.phase == TouchPhase.Began)
{
Vector3 wp = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
Vector2 touchPos = new Vector2(wp.x, wp.y);
if (GetComponent<Collider2D>() == Physics2D.OverlapPoint(touchPos)){
//Do Something
}
}
}
now i want it to be in 3D touching a Sphere
and i change the code as following
if (Input.touchCount == 1) {
Touch touch = Input.GetTouch(0);
if (Input.touchCount == 1 && touch.phase == TouchPhase.Stationary)
{
Vector3 wp = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
Vector3 touchPos = new Vector3(wp.x, wp.y, 0);
if (GetComponent<Collider>() == Physics.OverlapSphere(touchPos,0.5f)){
//Do Something
}
}
}
but it comes with error CS0019: Operator ‘==’ cannot be the applied to operands of type ‘UnityEngine.Collider’ and ‘UnityEngine.Collider’
i have no idea what should i change or how should i change in order to detect the touch collision in 3D
please someone can help me