- Home /
Full screen camera missing?
Hello everybody,
I have just started out with Unity and I am absolutely loving it, however, I stumbled on a pretty simple problem (I hope) that I cannot solve on my own. This is the situation:
I am making a first person shooter which will have x number of weapons. Among those, I have a rocket launcher. When the user holds the right mouse button, the Main Camera should switch to the rocket launcher camera.
Whenever I hold the right mouse button, the screen fills with the following message: "missing full screen camera". This is my current code for the camera switching:
public Camera playerCam;
public Camera rocketLauncherCam;
private void Start()
{
playerCam.enabled = true;
rocketLauncherCam.enabled = false;
}
private void Update()
{
if (Input.GetKey(KeyCode.Mouse1))
{
playerCam.enabled = false;
rocketLauncherCam.enabled = true;
}
else
{
playerCam.enabled = true;
rocketLauncherCam.enabled = false;
}
}
I cannot figure out what I did wrong. Enable one camera while disabling the other one, seemed like the way to go.
I hope this problem is easy to fix.
Thanks in advance and I really appreciate the time you take when you write an answer. Since the solution cannot be that hard, I do not ask for a large explanation. Just a quick overview, otherwise it would take too long (and I learn more by analyzing code).
Have a nice day,
Tahar
Answer by SkandYxyz · Oct 25, 2015 at 04:54 PM
I guess you didn't asigned:
public Camera playerCam; public Camera rocketLauncherCam;
Maybe use this instead.
public Camera playerCam; public Camera rocketLauncherCam;
private void Start() { playerCam = GameObject.Find("playerCam").GetComponent(); rocketLauncherCam = GameObject.Find("LauncherCam").GetComponent(); playerCam.enabled = true; rocketLauncherCam.enabled = false; }
private void Update() { if (Input.GetKey(KeyCode.Mouse1)) { playerCam.enabled = false; rocketLauncherCam.enabled = true; } else { playerCam.enabled = true; rocketLauncherCam.enabled = false; } } ,I guess Unity doesn't use
public Camera playerCam; public Camera rocketLauncherCam;
because you didn't initialized them right. Use this instead.
public Camera playerCam; public Camera rocketLauncherCam;
private void Start() { GameObject hand; playerCam.enabled = true; rocketLauncherCam.enabled = false; }
private void Update() { if (Input.GetKey(KeyCode.Mouse1)) { playerCam.enabled = false; rocketLauncherCam.enabled = true; } else { playerCam.enabled = true; rocketLauncherCam.enabled = false; } }
Hello SkandYxyz,
Thank your for your code snippet. I do really appreciate it. I am trying to change the tag first, since that would be the fastest solution. In case it did not work, I will try your code.
Thanks a lot for helping!
Tahar
I disabled the camera. Silly me! Sorry for wasting your time!
Answer by DiegoSLTS · Oct 25, 2015 at 01:54 PM
I'm not sure about this, but try switching the tag from your rocket launcher camera to MainCamera. I guess there should always be a camera with the MainCamera tag since some things depend on Camera.main.
Hello DiegoSLTS,
Thank you for your reply. I thought I has already tried this, but I will try it another time. I hope it works. If it works, I will mark your answer as the solution.
Thanks in advance,
Tahar
I disabled the camera. Silly me! Sorry for wasting your time!
Answer by pihar · Oct 26, 2015 at 03:57 PM
Hello everybody,
Thanks a lot for the responses, but I have already found the solution. I was being incredibly silly! I disabled the gun camera... I re-enabled it and there it was! Everything is working as it is supposed to.
Have a nice day!
Tahar
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Strange behaviour when switching camera 1 Answer
Switching from a cinematic cycle to the player camera 0 Answers
Distribute terrain in zones 3 Answers
C# Camera.main.GetComponent: Unknown Word SmoothFollow 0 Answers