- Home /
Question by
HarryFornasier · May 16 at 07:05 PM ·
animationocclusion cullingportals
Occlusion Portal with a door animation
I've set door occlusion portals on all of the doors in the scene.
You press e to open the doors and the open/close animation takes 1 second. I have set it so the occlusion portal is open when you press e. The problem is that when the door is open and you close the occlusion portal for half a second you can see it turning off and all the objects in that room turn off. I have tried to use an IEnumerator
timer to say that it waits for 2 seconds before turning it off when closing the door. However, if you spam e it will mess with the occlusion portal and turn it off and on at weird times when opening and closing the door.
What would you say is the best away to go about this? i'm pretty stuck.
Here's my code currently:
private void OnTriggerEnter(Collider other)
{
isInBox = true;
}
private void OnTriggerExit(Collider other)
{
isInBox = false;
}
void Update()
{
if (isInBox)
{
if (Input.GetKeyDown(KeyCode.E))
{
if (cooldown == false)
{
Debug.Log("how many");
runthis();
Invoke("ResetCooldown", 1.0f);
cooldown = true;
}
}
}
}
void ResetCooldown()
{
cooldown = false;
}
void runthis ()
{
if (!isPortalOpen)
{
OnOcclusion();
}
else
{
StartCoroutine(OffOcclusion());
}
}
IEnumerator OffOcclusion()
{
yield return new WaitForSeconds(1);
Debug.Log("Off Occlusion is running");
this.myOcclusionPortal.open = false;
isTimerFinished = true;
isPortalOpen = !isPortalOpen;
}
void OnOcclusion()
{
this.myOcclusionPortal.open = true;
isPortalOpen = true;
}
Comment