Actually, I am creating a snake 2D game, which is something I wanted to do from long time ago. I have created the design and the snake and the food spawn work as usual, but I would like to implement a mechanic, which if the snake passes a border either top, middle, bottom, right, left the snake comes from the opposite direction. I would like to know if anyone can help me with this? Thanks! Image: https://i.stack.imgur.com/i72lG.jpg
Code for the boundaries:
public class SnakeRespawn : MonoBehaviour
{
[SerializeField] private Transform player;
[SerializeField] private Transform respawnPoint;
void OnTriggerEnter2D(Collider2D collision)
{
player.transform.position = respawnPoint.transform.position;
// if (col.gameObject.CompareTag("Player"))
// col.transform.position = respawnPoint.position;
}
}