My friend and I are both making a 2d game with c# ,but we can’t figure out how to make an if statement to check whether two objects are touching so can anyone tell me the code needed to check if a player is touch the goal for example.
To check whether the player is touching a specific object:
- Go to your goal object
- In the inspector window go to tags
- Make a tag, for example “goal”
Add this code to your player object (make sure the player or goal has a RigidBody):
void OnTriggerEnter(Collider other)
{
if (other.transform.tag == "Goal")
// Do stuff
}
Hope this helped!