- Home /
Multiple cameras as child or assign coords/rot to main cam
There are several different "states" in my game, each distinct and focused on a different setup. Should I use just a single camera and change coords/rot, or should I assign the entire state to its own gameobject, including all the elements in that state, and the camera as well?
I don't quite follow. Do the states influence the camera control methods? Are we talking completely different control schemes etc here? I don't think the solution here should be completely one or the other- you should find some middle-ground that has the features you need.
The states influence the camera position and rotation, since the camera position is optimized for each state. Each state is a distinct bunch of mesh objects tied to an empty gameobject
Just enable/disable the cameras when you switch states. $$anonymous$$uch simpler that way. (I still don't quite understand your terms here, btw)
Answer by Owen-Reynolds · Nov 27, 2011 at 04:28 PM
I prefer to use one script on one camera, and move it based on the state:
// Common code for reading scrollwheel:
...
if(placingTowers) {
camSetUp1();
// spaceBar places towers, etc...
}
else camSetUp2();
A hidden benefit is if you are smoothing the camera (esp with lerp) then you can easily add smooths for switching camera modes (instead of snapping back, you quickly pull back.) Otherwise, camera code is rarely that long and it seems easier to keep it in one file.
A drawback is you can't directly find and adjust "fixed camera 3." If your cameras are different styles (Ortho, narrow view / perspective using render texture) you might use two cams to avoid having to change that in code (or if some things can't be changed in code.)
Performance-wise, I can't think of how either set-up would be better.
Hmm, so perhaps one ortho cam and one perspective cam. What about easily adjusting camera position/rotation in the editor, without getting in a mess?
If you have fixed cameras that never move, you may as well change between multiple cameras (one cam could use an array of Transforms, and transform=Cam[0];
but what's the point.)
But, for example, I have something with an "overlook" start menu cam, an "ai$$anonymous$$g" cam and a "follow the shot" cam. Even the overlook cam uses code (to position itself based on the size of the level.) I just put the code for all three in one script, using 1 cam total.
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
how do I get reference to a parent or a child? 2 Answers
Unity2D button as child of camera not clickable 1 Answer
How to check parent value instead name value(more details in post) 3 Answers
Display Name Above Object 2 Answers