How to make player go through object but can't go back

Hi,
I’m making a magic wall which allow player to go through but can’t go back. How to do this?

Pretty easy way would be to do this:

  1. Turn off the BoxCollider on the wall.
  2. Place a trigger on the other side of the wall which activates the BoxCollider when you step into it.

Example:

public GameObject theWall;

public void OnTriggerEnter () {
	theWall.GetComponent<BoxCollider>().enabled = true;
}

Assuming there would be nothing going through the wall apart from the player, this should work. If you have other things, use a Tag.

Well if its just linear movement you could put a box collider on the wal. Mark it as trigger, and then in your player script have this

function OnTriggerExit(other: Collider)
 { 	

     if(other.gameObject.tag == "WallTag")
     {

          other.IsTrigger = false;

     }

 }

Im not sure if that works or not but it makes sense to me. I usually on use C# so some of the syntax might me wrong. If your project is 2d use OnTriggerExit2. Remember you have to create a new tag a lnd put it in all the walls

On your wall object (Ensure the wall has a BoxCollider) add a new script and inside the script add the code below. :

function Start () {
   GetComponent<BoxCollider> ().enabled = false;
}

function OnCollisionExit(other: Collision)
{     
    if(other.gameObject.tag == "Player")
    {
          GetComponent<BoxCollider> ().enabled = true;
     } 
}