Noob needs help with 2D Box Colliders!

Hello there! I am working on a game project for my APCSP class. I am supposed to create a game using Unity. Unfortunately, I have absolutely no idea what I am doing; I do not know how to use C# or the Unity engine.
I am essentially recreating a Pacman-esque game. I currently have the sprite and maze set up. I have also managed to get my character to move, but he will go through the walls of the maze, which is my main challenge. I would like for him to, not necessarily stop, but not go through the maze’s walls (i.e. acknowledge their presence).
I have a Circle Collider 2D and Rigidbody2D on my “Pacman,” and Box Colliders 2D on the walls of my maze.
Would I need to add something to my script? Or would I have to create another script altogether?
This is what I have for the movement script:
using UnityEngine;
using System.Collections;

public class SunshineMove : MonoBehaviour
{
public float speed = 1.5f;

void Update()
{ if (Input.GetKey(KeyCode.LeftArrow))
{
transform.position += Vector3.left * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.RightArrow))
{
transform.position += Vector3.right * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.UpArrow))
{
transform.position += Vector3.up * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.DownArrow))
{
transform.position += Vector3.down * speed * Time.deltaTime;
}
}
}

Please help me. I am on a tight deadline; and I have tried watching videos on YouTube, but they have a different idea than what I would like to achieve.
Thank you,
Mika

As you have discovered you can’t simply set the position as you’ll simply set pacman’s position inside the wall! Instead you need to let pacman be moved by the physics engine by setting his velocity.

rigidbody2D.velocity = newVelocity;

Note that when changing rigidbodies you should do this inside FixedUpdate() instead of Update() otherwise you may get some odd behaviour.

As for integrating this into your code, I’ll leave the rest as an activity for the reader.

Related Reading: