I made a script that used ontriggerstay to make a code lock, the script is supposed to wait for the user to enter a number, in this case I made the only number 0 just to test it. Once you input 0 it sets a Boolean for the first number to false and one for another number to true. I do this so I can enter different numbers for a combination. However when I test my code it correctly accepts the first number and sets the Booleans but refuses to accept the other inputs.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CodeLock : MonoBehaviour {
public string[] password;
public bool[] locks;
// Use this for initialization
void Start () {
locks[0] = true;
}
// Update is called once per frame
void Update () {
}
void OnTriggerStay(Collider other)
{
if(other.tag == "Player")
{
if (Input.anyKeyDown || locks[0] == true){
if(Input.inputString == "0" )
{
password[0] = "0";
locks[0] = false;
locks[1] = true;
}
}
else if (Input.anyKeyDown || locks[1] == true)
{
if (Input.inputString == "0")
{
password[1] = "0";
locks[1] = false;
locks[2] = true;
}
}
else if (Input.anyKeyDown || locks[2] == true)
{
if (Input.inputString == "0")
{
password[2] = "0";
locks[2] = false;
locks[3] = true;
}
}
else if (Input.anyKeyDown || locks[3] == true)
{
if (Input.inputString == "0")
{
password[3] = "0";
locks[3] = false;
}
}
}
}
}