Hi guys!
I’m currently in the process of making a game, that requires me to switch to another camera (than the first person controller camera I’m primarily using).
However, When i use the cam1.camera.active = false, It turns off my ability to move my main camera around (which also makes my character act a bit strange, as i have some objects bound to the main camera (A flashlight).
How can i keep the mouse.Y still active, while the camera it is bound to, is turned off?
(My script attached)
static var CurrentCamera = 1;
var cam1 : GameObject;
var cam2 : GameObject;
function Update ()
{
if (CurrentCamera == 1)
{
cam1.camera.active = true;
cam2.camera.active = false;
}
if (CurrentCamera == 2)
{
cam1.camera.active = false;
cam2.camera.active = true;
}
CameraSwitch();
}
function CameraSwitch()
{
if(Input.GetKey("3"))
{
CurrentCamera = 1;
}
if(Input.GetKey("4"))
{
CurrentCamera = 2;
}
}
if you only want to make it so that you see the perspective on each camera on switch you may need to rather than deactivate and activate each camera change the draw priority of each camera on the switch such as changing the depth or camera layer. Thats my two cents about this maybe there is a better way. Good luck!
I know the Depth drill, but is that seriously how people “Switch”? Is that efficient in any way? I kinda have the perception of the camera “in the background” is taking a lot of resources
I’m shocked that you bind functionality beyond displaying the game to your camera. Poorly defined classes lead to unmaintainable code, which is what you’re facing now.
It doesn’t offend anyone, but you’re hurting yourself. Classes (and objects) should have well defined functionality, ideally they are defined before they are put into code.
Also, if you want to disable a camera, but not the object, disable the component. Your code deactivates the entire gameObject. You have cam1 and cam2 as GameObjects, but maybe they should be the actual Camera components themselves.
Can you give me an example of something “Defined the right way”? I really want to learn from your critique!
Sorry if I’m asking for too much, I’ve just never had anyone feel so strongly, about my small coding projects!
Software engineering is as much, if not more, planning over typing code. It’s important to look at each object and understand how you wish for it to interact with other objects. Making it up as you go can work for very small projects, but it doesn’t scale well.
As for defining something the right way, it should be maintainable and sensible and sadly those are both subjective terms. If you have to make more scripts, make them, you have as many as you’d like. On these forums, there is a serious shortage of powerful tools such as inheritance, polymorphism, events, and interfaces. In the long run, people will be much more productive if they learn the tools and how to use them.
The tone in this is part of the problem and it’s antithetical to egoless programming. You mentioned this as if it cannot be changed. If the design is broken, fix the design instead of trying to code around it.
I totally get your point. However, from my skill level (and my approach to programming), “work-arounds” just seems to be the way to go (hold on, I’m not done!).
The reason for this, is solely because I’m not experienced enough, due to my background lacking “words of wisdom”, from someone who knows his/her “shit”.
I’ve always loved, “discovering” things and mindsets, as it allows a lot of change. This will without a doubt change my approach to a lot of things (programming related, obviously). I lack a lot of “rules” and “do’s and don’ts”, so thanks for the heads up.
Well, don’t worry too much about having to scrap a design. It happens to new programmers and great programmers (and often to the mediocre ones, such as myself). Trust me, when you implement a better design, it’s far more satisfying than getting a workaround to work around the actual problem.
I find it funny how on the programming for a game, you have to pre plan the specific objects, but in HTML, and CSS you barely have to do that you just need an idea on what you are making, and plus you can just go edit the items later and make them native to a certain thing, which can be done, like create a quick script that does what you need loads the game fine but isn’t very organized, and then later specisize the objects later, at the same time you do it for the code and objects, and then test it, but keep a back up just incase. but for HTML it’s much easier but backing up the file is pretty much the same. also try to keep the codes as short as possible with having maximum functionality, you don’t want your project to lag, and if you have a log for your code, keep it on a seperate file, so it doesn’t interfere with the codes size, and doing all this can be done in a text document, although i don’t recommend it unless it is for HTML, Javascript, or CSS, though web programmers have been using game editors that can edit javascript recently. but pre-planning a project, and pre-creating small and re-editing small details is a smart thing to do, as it saves you time and frustration.