Basically I am working on side scrolling 2d game. For that I want to check whether player is collided with wall. I have written some code for it but can't able to decide where I have done stupid mistake. So please guide me in this. If you need any more details then I am always available.
Code for detecting wall :
RaycastHit2D hit = Physics2D.Raycast (wallCheck.position, Vector2.right, wallCheckDistance);
if (Physics2D.Raycast (wallCheck.position, Vector2.right, wallCheckDistance)) {
Debug.Log ("collider name : " + hit.collider.name);
isDead = true;
}
Debug.DrawRay (wallCheck.position, Vector3.right * wallCheckDistance, Color.red);
Following image gives you all idea about situation. In that I have allocated player with groundCheck and wallCheck flag. At present in wallCheck section, I am detecting ground as collider response after execution of above code. Above code I have placed in Update method for continuous checking.
For this game, I want to do game over if wallCheck object detect any object in collision.
Why wallCheck object detecting collision of ground object (stage1a)? That is big question of mine.