I am learning to create a snake game (from this tutorial) .
The problem is arising when the object(Snake) collides with the borders,nothing happens and it moves out of the box (white square on the left).
I have added BoxCollider2D
components on the bounds.
For the player (Snake), I've added BoxCollider2D
component and Rigidbody2D
.
Here's the script attached to the snake
using UnityEngine;
using System.Collections;
public class Snake : MonoBehaviour {
Vector2 dir=Vector2.left;
// Use this for initialization
void Start () {
InvokeRepeating ("Move", 0.3f, 0.3f);
}
// Update is called once per frame
void Update () {
}
void Move(){
transform.Translate (dir);
}
}