Scenario:
I have a door that is triggered open by a pressure plate. In some cases I want the door to trigger open only by multiple pressure plates at the same time.
What I want is to check the list of pressure plates to se if the are all triggered so I can open the door.
What I have now finds the script of all pressure plates in the scene and not the list, and it only checks the last script in my array is true, to open door.
Hope someone can help me in the right direction :)
Heres my code:
private presurePlateScript presurePlateScript;
public List padList = new List ();
//private List padListScript = new List ();
public bool openDoor;
public presurePlateScript[] _padListScript;
// Use this for initialization
void Start () {
openClose = false;
foreach(GameObject go in padList) //for every object
{
_padListScript = FindObjectsOfType(typeof(presurePlateScript)) as presurePlateScript[];
}
}
// Update is called once per frame
void Update () {
foreach(presurePlateScript sc in _padListScript)
{
if(sc.isPlateTrigger == true)//if the boolean is true then win
{
openDoor = true;
}
else
{
openDoor = false;
}
}
if(openDoor)
{
StartCoroutine(doorOpen(gameObject.transform, doorPosB, 0.3f));
}
if(!openDoor)
{
StartCoroutine(doorClose(gameObject.transform, doorPosA, 0.3f));
}
↧