Home Game Development unity – Close door after participant has entered a room

unity – Close door after participant has entered a room

0
unity – Close door after participant has entered a room

[ad_1]

I can not work out easy methods to make the triggered door open after which shut once more. I managed to open the door, however cannot determine easy methods to shut it once more as soon as the participant is contained in the room. Here’s my code thus far:

public GameObject upDoor;
public GameObject downDoor;
public bool openDoor;

void Update()
{
    if(openDoor) //(openDoor == true)
    {
        upDoor.remodel.Translate(Vector3.up * Time.deltaTime);
        downDoor.remodel.Translate(Vector3.down * Time.deltaTime);
    }
    
}

void OnTriggerEnter(Collider different)
{
    Debug.Log("Trigger Entered");
    openDoor = true;
}

void OnTriggerKeep(Collider different)
{

}

void OnTriggerExit(Collider different)
{
    openDoor = false;
}

This is how I edited the code, however I’m having a compile error.. I do not know what else I might do?

I attempted else->return false; however that might trigger an error as properly.

void Update()
{
    if(openDoor) //(openDoor == true)
    {
        upDoor.remodel.Translate(Vector3.up * Time.deltaTime);
        downDoor.remodel.Translate(Vector3.down * Time.deltaTime);
    }
    else
    {
        upDoor.remodel.Translate(Vector3.down) * Time.deltaTime);
        downDoor.remodel.Translate(Vector3.up * Time.deltaTime);
    }
    
}

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here