- Home /
Question by
GaelleChar · Jan 27 at 11:12 PM ·
cameracoroutinecameras
How to get a camera state to wait with coroutine?
Fairly new to Unity I wanted to know how to keep a camera in a state while the player is shooting. There are two cameras in the scene and for now, it does switch, but for 0.01 sec before switching back to the main camera. Thank you!
Using: https://docs.unity3d.com/Manual/MultipleCameras.html and https://docs.unity3d.com/ScriptReference/MonoBehaviour.StartCoroutine.html
void CheckStates(){
switch(state)
{
case State.gunNotEquipped:
DoGunNotEqipped();
break;
case State.gunEquipped:
if(Input.GetKeyDown(KeyCode.E)){
StartCoroutine(DoGunEqipped());
}
break;
default:
break;
}
}
IEnumerator DoGunEqipped(){
defaultCamera.enabled = false;
firstPersonCamera.enabled = true;
gunClicked = true;
while(firstPersonCamera.enabled == true){
if(Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.G)){
ShootBullet();
Debug.Log("Shooting");
}
Debug.Log("Shoot with right click");
yield return new WaitForSeconds(45f);
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Camera Switching 1 Answer
Second camera dissappears when level is reset 1 Answer
how to have one script reffer to another 0 Answers
camera rotation help in bolt script 0 Answers