I'm in the middle of a game jam and I've been looking for 3 hours why my RaycastALL doesn't detect every collision. Here's the bit of code that handles this. Thank you very much for your time. I'm available to answer all your questions regarding my project :
case (PlayerState.CarryingRaw):
//Debug.Log("Carrying" + pickedUpRawItems.Count + "items");
//Debug.Log(pos.x +","+ pos.y);
hits = Physics2D.RaycastAll(transform.position, new Vector2(pos.x-5,pos.y),20,8);
Debug.DrawLine(transform.position, new Vector2(pos.x - 5, pos.y), Color.red, 2);
for (int i = 0; i < hits.Length; i++)
{
Debug.Log(hits[i].transform.name);
}
//Debug.Log("Raycasted" + hits.Length + "Objects");
for (int i = 0; i < hits.Length; i++)
{
{
if (hits[i].transform.tag == pickedUpRawItems[pickedUpRawItems.Count - 1].transform.tag)
{
Debug.Log(hits[i].transform.tag);
Debug.Log(pickedUpRawItems[pickedUpRawItems.Count - 1].transform.tag);
hits[i].transform.GetComponent<BoxCollider2D>().enabled = false;
hits[i].transform.GetComponent<ItemScript>().currentState = ItemScript.ObjectState.PickedUp;
hits[i].transform.localScale = sizeChange;
pickedUpRawItems.Add(hit.transform.gameObject);
}
}
}
break;
case (PlayerState.Working):
break;
case (PlayerState.Free):
Debug.Log("youhou + State.Free");
hit = Physics2D.Raycast(transform.position, new Vector2(pos.x - 5, pos.y));
if (hit)
{
hit.transform.GetComponent<BoxCollider2D>().enabled = false;
Debug.Log("youhou + hit.Free");
hit.transform.GetComponent<ItemScript>().currentState = ItemScript.ObjectState.PickedUp;
hit.transform.localScale = sizeChange;
pickedUpRawItems.Add(hit.transform.gameObject);
currentState = PlayerState.CarryingRaw;
}
break;