Question by
Sv3r · Jun 27, 2019 at 10:36 PM ·
c#programmingwaitforseconds
WaitForSeconds Does not work,WaitForSeconds Problem
When i start the game waitforseconds does nothing
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Trigger : MonoBehaviour
{
public GameObject Scare;
public AudioSource audiosource;
public AudioClip ScareSound;
public Camera FirstPersonCam, ThirdPersonCam;
public bool camSwitch = false;
private void Start()
{
Scare.SetActive(false);
}
void OnTriggerEnter(Collider other)
{
camSwitch = !camSwitch;
FirstPersonCam.gameObject.SetActive(camSwitch);
ThirdPersonCam.gameObject.SetActive(!camSwitch);
Scare.SetActive(true);
audiosource.PlayOneShot(ScareSound);
StartCoroutine("wait");
}
IEnumerable wait()
{
yield return new WaitForSeconds(3);
Scare.SetActive(false);
camSwitch = !camSwitch;
FirstPersonCam.gameObject.SetActive(camSwitch);
ThirdPersonCam.gameObject.SetActive(!camSwitch);
}
}
Comment
Where is this script attached? $$anonymous$$eep in $$anonymous$$d that a disabled gameObject can't run coroutines.
Have you tried to put Debug.Log inside the wait function, before and after the yield return?
Your answer
Follow this Question
Related Questions
IEnumerator Not Completing Entire Function 0 Answers
In Game Programming Language 1 Answer
Instantiate no longer working? 3 Answers
Delete item in inventory 0 Answers