- Home /
How to change physics,lighting, and camera when a specific input is entered in-game?
I am creating a game where the player is able to switch between top down view and side scroller. When a button, say spacebar, is pushed, the camera, lighting and physics would need to switch to a top down perspective (or vise versa) . I have already written scripts for the side scroller and top down controls/physics, but I don't know how to switch between them in-game.
Ps. I am very sorry that I am asking with out contributing. I am currently learning to program and I will begin to contribute. I am just in over my head with a rapidly approaching deadline.
Edit: I would not need the camera to change in any way.
Please post your two scripts so we can see what/how is changing between the two views.
Unfortunately, I will not be able to Access the script until Tuesday. Can't you just write a command that says something along the lines of: "If input = space apply TDS scripts to shape"?
Well, you can do something like:
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space)) {
tds.enabled = true;
}
But there is only a slim chance this will be a perfect fit to your code:
You will have to know how to initialize the 'tds' to point to the TDS script on that specific object.
you probably want to disable some other script at the same time.
Since disabled scripts don't get Updates(), the above code will have to be on a third script so that it is not disabled when the TDS script is disabled. That means you are going to need to figure out how to reference scripts on other game objects.
Disabling a script only disables some things. Without a look at the scripts, I cannot spot the potential issues.
Based on your description, you may have to move or rotate the camera.
There may be simpler solutions to disabling/enabling scripts. For example, you may what multiple cameras, so you enabled or disable the whole camera rather than individual scripts.
Answer by MattDahEpic · May 07, 2014 at 01:31 AM
Without the scripts to reference, I think you would want something along the lines of, meaning you'll have to adapt it to your problem. If you were to group all of the physics, lighting, and camera into a single GameObject
, you could just enable/disable that object.
Code:
var sideCam : GameObject; // you'd have to define this in the editor
var topCam : GameObject; // this too
public var onTop : boolean = true; // should you want to start out on top, set this to true
public var onSide : boolean = false; // and set the other to false
function Update () {
if (Input.GetKeyDown(KeyCode.Space) && onTop == true) { //flip to side
onTop = false;
onSide = true;
sideCam.enabled = true; //enable side cam
topCam.enabled = false; //disable top cam
}
if (Input.GetKeyDown(KeyCode.Space) && onSide == true) { //flip to top
onTop = true;
onSide - false;
sideCam.enabled = false; //disable side cam
sideCam.enabled = true; //enable top cam
}
}
Being that the topCam
and sideCam
are GameObject
s then you could pile your physics and control scripts inside of those objects
If you were to group all of the physics, lighting, and camera into a single GameObject, you could just enable/disable that object.
Answer by Jeff-Kesselman · May 07, 2014 at 01:30 AM
It sounds like you are trying to combine two 2D games.
Why not implement it as 3D and just change the camera when the user presses a button? Then you don't have to worry about changing physics or synchronizing two totally different sets of gameplay?
I think I was a bit unclear. Think of it as a side scroller platforms rand when a button is pushed, you would then walk on what was the background in a Tds-like controls.