- Home /
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);
}
}
Your answer
Follow this Question
Related Questions
Issue With Simultaneous ReadPixels Calls 0 Answers
Switching Between Cameras JavaScript 0 Answers
Render a list of objects into a Texture2D array 0 Answers
Can I make a camera that has an orthographic vertical axis, but a perspective on the horzontal axis? 1 Answer
How does ScreenToWorldPoint work with split screen with multiple cameras? 1 Answer