I have a Player object with a BoxCollider2D
component and a Ladder object also with a BoxCollider2D
component. Each object has a script, and in each script, I set up references to the box colliders in the normal way.
public BoxCollider2D box_collider;
void Start ()
{
box_collider = GetComponent<BoxCollider2D>();
}
My player script is called "PlayerController", so that's the class defined in the script.
In my Ladder's script I have the following:
void Update ()
{
GameObject player = GameObject.Find("Player");
PlayerController player_controller = player.GetComponent<PlayerController>();
if (player_controller.box_collider.bounds.Intersects (box_collider.bounds))
Debug.Log ("collision");
else
Debug.Log ("no collision");
}
This script invariably returns "no collision" and I'm not sure why.
Any ideas?