So I’m making a FNAF Fan game, but I started it in 3D but that’s not the case.
I was making the door system and I have a corountine that counts a random time and when it reaches the end it will make a jumpscare. But when i close the door and stop the corountine, it wouldn’t restart and when I will start it again it will continue from where it was stopped. I tried counting the time when the door was open and closed but I can’t get it working. If anyone could respong it would mean a lot.
This is my code:
Update()
{
if (goToDoorLeft)
{
Coroutine Jumpsc = StartCoroutine(WaitBeforeJumpscare());
agent.SetDestination(doorPointLeft.transform.position);
if (gm.door1.doorIsOpening == false)
{
StopCoroutine(Jumpsc);
if (!hasCheckedT)
{
closedDoor = Time.time;
closedDoor -= timeWhileOpen;
closedDoor += randomTime;
Debug.Log(randomTime);
Debug.Log("Has closed at " + Time.time);
hasCheckedT = true;
}
}
else
{
if (!hasCheckedOpen)
{
timeWhileOpen = Time.time;
Debug.Log(Time.time + "Has been opened");
hasCheckedOpen = true;
}
}
IEnumerator WaitBeforeJumpscare()
{
yield return new WaitForSeconds(randomTime);
if (left)
{
Coroutine Jumpsc = StartCoroutine(WaitBeforeJumpscare());
if (gm.door1.doorIsOpening)
{
gm.Jumpscare(gameObject.name);
Debug.Log(gameObject.name);
}
else
{
StartCoroutine(WaitBeforeLeavingLeft());
StopCoroutine(Jumpsc);
}
}
}