I’ve considered the final solution you gave me and just using the same camera, but I want several cameras that show specific layers for effect, and this seemed easier but apparently I was wrong about that since I can no longer control my character when I swap cameras.
As far as setup, I used the built in 3rd person controller and selected the ‘Main Camera’ as the one to follow the player… position in relation to the ‘player1’ game object (the main character) is done via code. When a battle sequence starts, I cut to a second camera which hides certain layers and then pans to the side and enemies are displayed on the opposite side of the screen. This all seems to work perfectly.
I have tested the ‘input’ key using a print statement and it works up until I swap the cameras. Here is the code for swapping cameras :
var worker : GameObject = GameObject.Find("construction_worker");
randAttack = 0;
battleCamera.transform.position = moveCamera.transform.position;
battleCamera.transform.rotation = player1.transform.rotation;
moveCamera.camera.enabled = false;
battleCamera.camera.active = true;
battleCamera.camera.enabled = true;
player1.gameObject.GetComponent(ThirdPersonController).isControllable = false;
var enemy1 = Instantiate(enemy1, player1.transform.TransformPoint(Vector3.forward * 12), Quaternion.identity);
enemy1.transform.LookAt(player1.transform);
var enemy2 = Instantiate(enemy2, enemy1.transform.TransformPoint(Vector3.left * distBetweenMobs), Quaternion.identity);
enemy2.transform.LookAt(player1.transform);
var enemy3 = Instantiate(enemy3, enemy1.transform.TransformPoint(Vector3.right * distBetweenMobs), Quaternion.identity);
enemy3.transform.LookAt(player1.transform);
the code above just sets the ‘battlecam’ to the same position and rotation as the main camera so it is a seamless transition (minus the fact that layers are hidden) and then pans to side and out in front of the player character. the player stops, and on the opposite side of the screen (now being viewed from the side rather than behind the player) the enemies are loaded.
What the problem is, the player can jump, move, etc. before the random battle occurs. Once I swap cameras, all input from the keyboard is no longer being recorded, regardless of whether it is in the character controller or attached to the battle camera. I feel like I’m just missing something simple that would allow keyboard input for when swapping to the battle camera but I cannot find a solution for the life of me.
Currently the only script attached to the battle camera is the one to script it’s movement.
I’m sure my code is very amateur, but for now it works. I’ve been coding in other languages for a very long time but am pretty new to Unity, but this is how I learn. Tutorials help me up to a point, but I have to jump in, break things, try new things, etc. in order for me to figure out why things work a certain way… which is what I’m attempting to do now, but I cannot figure out why I can’t use keys when I swap cameras… it seems so counter-intuitive to me.
PS. The ‘enabled’ and ‘active’ things are from attempts to figure this out. My original code ONLY set the maincam.active to false and the battlecam.active to true.