- Home /
OnCollisionEnter2D Not Working??
i m making on 2d game
i want the stop my player when touch finish(success line). but when my player touch success line nothing happened??
TouchControll.cs
void OnCollisionEnter2D(Collision2D col) //put this script on player game object
{
if(col.gameObject.tag== "successfinishtag") //tag of finish line
{
Debug.Log("OnCollisionEnter2D");
//when player touch finish line i want to the stop my player //nothing happend
Gamemanager.stopsplayer = true; //player stop
}
}
Image:
Finishline have Rigidbody2D?? why colllision2D not work ??
Answer by I_Am_Err00r · Aug 12, 2019 at 03:36 PM
The only thing I can think of is that you don't have the tag defined in the FinishLine or maybe you are capitalizing "successfinishtag" in the inspector or it is not spelled correctly, string references have to be EXACT (in both spelling and case) for them to match.
Personally, I would use a tag of "Finish" or something simple like that.
@I_Am_Err00r thanks sir give the answer i giving a tag finish line:
see my image:
So was that the issue, just not have a tag definition? Are you still having trouble? If you are, is it at least logging in the console that Debug.log("OnCollisionEnter2D") you put in there?
@I_Am_Err00r this link say :https://docs.unity3d.com/$$anonymous$$anual/CollidersOverview.html
if u have two rigidbody on your gameobject then collision is posiiblem??can u agree with this? but i put rigidbody both of them(Player,Finishline) collision not run??
Your answer
Follow this Question
Related Questions
Player not taking damage on collision with enemy 1 Answer
How can I make walls with Collider2D components for a top-down game in Unity 2018? 1 Answer
2d rigidbody falling from the collider when it is moved 3 Answers
Collision Between 2D Rigidbodies is Jittery (No Movement) 1 Answer
OnCollissionEnter2D not being called 1 Answer