I am trying to execute a function only when two objects, one of type “touchArea” and other of type “Tiles” . For that purpose, I did this
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Vector3 mousePos = Input.mousePosition;
mousePos.z = 10;
Vector3 screenPos = GameCamera.ScreenToWorldPoint(mousePos);
RaycastHit2D hit = Physics2D.Raycast(screenPos, Vector2.zero);
if (hit)
{
if(hit.collider.tag=="touchArea" && hit.collider.tag == "tiles")
{
print(hit.collider.name);
}
}
}
It works fine when only looking for one type, but when looking for two that are overlapping, it doesnt work. One of them is a trigger type. Thanks in advance.