public bool isMatch(GameObject gameObject1, GameObject gameObject2) { Tiles ts1 = gameObject1.GetComponent <Tiles>(); Tiles ts2 = gameObject2.GetComponent <Tiles>(); return(ts1 != null && ts2 != null && type == ts1.type && type == ts2.type && ts1.CompareTag("Tile") == true && ts2.CompareTag("Tile") == true); }