Cracking the Picture Code Sequence | VR Unity Developer
With the pictures now properly put in their frames, it’s time to place them correctly into their sockets so the player can move on to the next sequence to escape the room. There’s no immediate danger or anything, but I doubt any player wants to stay here longer than they have to.
Get Derek Anderson’s stories in your inbox
Join Medium for free to get updates from this writer.
Before I demonstrate the correct sequence, there are a few housekeeping items I forgot to mention. I set the Interaction Layer Mask for the socket interactors for the picture frames to Frame. I also assigned to Frame as well in the Interaction Layer Mask for each picture frame GameObject that the player can interact with.
The player won’t be able to move on to the next step unless the pictures are placed in the correct order. Each picture frame that is required to complete this sequence has the FrameID script attached to them, which identifies the ID assigned to the specific picture frame. The FrameLock script will get the ID of the picture frame (if it has one) and enter it into the code. If the code sequence is correct, it will activate the next step of the escape room.
public class FrameLock : MonoBehaviour
{
[SerializeField] int[] _lockCode = new int[3] { 1, 2, 3 };
int[] _enteredCode = { 0, 0, 0 };
private XRSocketInteractor[] _interactors;
[SerializeField] UnityEvent _onCheck;
private void Start()
{
_interactors = GetComponentsInChildren<XRSocketInteractor>();
}
public void EnterSocket0()
{
var interactables = _interactors[0].interactablesSelected;
FrameID id = interactables[0]?.transform.GetComponent<FrameID>();
if (id != null)
{
_enteredCode[0] = id.GetID();
if (CheckCode())
_onCheck.Invoke();
}
}
...
private bool CheckCode()
{
if (_enteredCode.Length == _lockCode.Length)
{
for(int i = 0; i < _enteredCode.Length; i++)
{
if (_enteredCode[i] != _lockCode[i])
return false;
}
return true;
}
else return false;
}
}Only a few picture frames are needed to activate the next step, but the socket interactors are set to accept all picture frames assigned in the Interaction Layer Mask to Frame, not just specific ones. This will allow any picture frame to be placed into the socket interactors, but unless they are assigned an ID from the FrameID script, they won’t be helpful in moving on to the next step.
There will be clues to help the player figure out the right order. For the purpose of this demonstration, there will be an audio sound that will play and the desk should disappear, or be disabled. The desk won’t disappear in the finished project, but this is just to check to make sure the code sequence plays out properly.
I already gave a sneak peek at what the pictures will potentially be for this escape room, so I disabled them for this demonstration. Rest assured, the pictures will be there so the player can escape this room.








