Multi camera problem!

Hi I´m new here!

The first step on Unity3D world!

I have a main camera and 4 inspector(free) cameras.
The problem is I have a Main camera with Third person view for the character, the camera is not following the character any more after I created 4 more cameras. And when I move one camera all the others are moving as well. I have a script that switch cameras when I hit the keys from 1-5. How can I make the main camera follow the character again? How can I make the four free camera move independent from each other. The script that I use enable true and false.

Hope someone understand me?
Thanks in advance on reply!

I have solved 1 problem now, that the camera is now following the charater.
I change all the 4 free camera to the same name camera instead camera1, camera2…
Strange that it works like that!

So now the only thing is left is how to move the 4 free flying camera independently.
They all have the same move keybutton,

Inset for move up,
home for forward,
Pageup for move down,
delete for leftmove,
End for move back,
PageDown for move right.

So what is the solution for that?

You should probably show your script(s) so we can better assess the problem.

It locks like this
Its cs

using UnityEngine;
using System.Collections;

public class CompassCam : MonoBehaviour 
{ 
	public Camera camera1;
	public Camera camera2; 
	public Camera camera3; 
	public Camera camera4;
	public Camera camera5; 	
	
	void Update () 
	{ 
		
		if (Input.GetKey ("2")) 
		{ 
			camera1.enabled = false; 
			camera2.enabled = true; 
			camera3.enabled = false; 
			camera4.enabled = false;
			camera5.enabled = false; 	
		}
		 
		if (Input.GetKey ("1")) 
		{ 
			camera1.enabled = true; 
			camera2.enabled = false; 
			camera3.enabled = false; 
			camera4.enabled = false;
			camera5.enabled = false; 	
		} 
		
		if (Input.GetKey ("3")) 
		{ 
			camera1.enabled = false; 
			camera2.enabled = false; 
			camera3.enabled = true; 
			camera4.enabled = false;
			camera5.enabled = false; 	
		} 
		
		if (Input.GetKey ("4")) 
		{ 
			camera1.enabled = false; 
			camera2.enabled = false; 
			camera3.enabled = false; 
			camera4.enabled = true;
			camera5.enabled = false; 
		}
	}
}

Sorry somthing is missing in the code!

code:

using UnityEngine;
using System.Collections;
public class CompassCam : MonoBehaviour
{
public Camera camera1;
public Camera camera2;
public Camera camera3;
public Camera camera4;
public Camera camera5;

void Update ()
{
if (Input.GetKey (“2”))
{
camera1.enabled = false;
camera2.enabled = true;
camera3.enabled = false;
camera4.enabled = false;
camera5.enabled = false;
}
if (Input.GetKey (“1”))
{
camera1.enabled = true;
camera2.enabled = false;
camera3.enabled = false;
camera4.enabled = false;
camera5.enabled = false;
}
if (Input.GetKey (“3”))
{
camera1.enabled = false;
camera2.enabled = false;
camera3.enabled = true;
camera4.enabled = false;
camera5.enabled = false;
}
if (Input.GetKey (“4”))
{
camera1.enabled = false;
camera2.enabled = false;
camera3.enabled = false;
camera4.enabled = true;
camera5.enabled = false;
}
if (Input.GetKey (“5”))
{
camera1.enabled = false;
camera2.enabled = false;
camera3.enabled = false;
camera4.enabled = false;
camera5.enabled = true;
}
}
}

If you have the same movement script attached to all 4 of the independently moving cameras then they will all detect the movement keys and all move at the same time. If you only want the active camera to move, you could try something like this in your script.

if (Input.GetKey("home")  camera.enabled)
{
    //Your camera movement code for the home key
}

I haven’t tested this, but I think it should work for only moving the active camera.

Hi thankyou for awnser MegadethRocks!!!

My key is 1 the for Main Camera that use WASD and the arrows for the movement, key 2 is for the free camera and use Insert,home,pageup,delete,end,pagedown for movement same for key 3,4,5

This is my script for the FlyCam movement.
I put your code in the middle and change it to the 2 key button. But it dident work, All the camera moves.
Hope you can see whats wrong!
Thanks again for your time!

var sensitivity : float = .1;
var moveSpeed : float = 5;
var moveSpeedUpDown: float = 2;

if ( Input . GetKey( “2” ) camera.enable)
{

function Update() {
transform.Rotate(Vector3.up * Input.GetAxis(“Mouse X”) * Time.deltaTime * sensitivity);
transform.Translate(Vector3.forward * Input.GetAxis(“Home”) * Time.deltaTime * moveSpeed);
transform.Translate(Vector3.right * Input.GetAxis(“Home2”) * Time.deltaTime * moveSpeed);
transform.Translate(Vector3.up * Input.GetAxis(“UpDown”) * Time.deltaTime * moveSpeedUpDown);

}

@script RequireComponent(CharacterController)

It dident work, all the camera still moves!

var sensitivity : float = .1;
var moveSpeed : float = 5;
var moveSpeedUpDown: float = 2;

if ( Input . GetKey( “2” ) camera.enable)
{

function Update() {
transform.Rotate(Vector3.up * Input.GetAxis(“Mouse X”) * Time.deltaTime * sensitivity);
transform.Translate(Vector3.forward * Input.GetAxis(“Home”) * Time.deltaTime * moveSpeed);
transform.Translate(Vector3.right * Input.GetAxis(“Home2”) * Time.deltaTime * moveSpeed);
transform.Translate(Vector3.up * Input.GetAxis(“UpDown”) * Time.deltaTime * moveSpeedUpDown);

}
{

if ( Input . GetKey( “3” ) camera.enable)
{

function Update() {
transform.Rotate(Vector3.up * Input.GetAxis(“Mouse X”) * Time.deltaTime * sensitivity);
transform.Translate(Vector3.forward * Input.GetAxis(“Home”) * Time.deltaTime * moveSpeed);
transform.Translate(Vector3.right * Input.GetAxis(“Home2”) * Time.deltaTime * moveSpeed);
transform.Translate(Vector3.up * Input.GetAxis(“UpDown”) * Time.deltaTime * moveSpeedUpDown);

}
{

if ( Input . GetKey( “4” ) camera.enable)
{

function Update() {
transform.Rotate(Vector3.up * Input.GetAxis(“Mouse X”) * Time.deltaTime * sensitivity);
transform.Translate(Vector3.forward * Input.GetAxis(“Home”) * Time.deltaTime * moveSpeed);
transform.Translate(Vector3.right * Input.GetAxis(“Home2”) * Time.deltaTime * moveSpeed);
transform.Translate(Vector3.up * Input.GetAxis(“UpDown”) * Time.deltaTime * moveSpeedUpDown);

}
{

if ( Input . GetKey( “5” ) camera.enable)
{

function Update() {
transform.Rotate(Vector3.up * Input.GetAxis(“Mouse X”) * Time.deltaTime * sensitivity);
transform.Translate(Vector3.forward * Input.GetAxis(“Home”) * Time.deltaTime * moveSpeed);
transform.Translate(Vector3.right * Input.GetAxis(“Home2”) * Time.deltaTime * moveSpeed);
transform.Translate(Vector3.up * Input.GetAxis(“UpDown”) * Time.deltaTime * moveSpeedUpDown);

}

@script RequireComponent(CharacterController)

You should only have 1 Update function and it shouldn’t be inside of an if statement. Try this instead.

function Update(){
   if (camera.enabled)
   {
      transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * Time.deltaTime * sensitivity); 
      transform.Translate(Vector3.forward * Input.GetAxis("Home") * Time.deltaTime * moveSpeed); 
      transform.Translate(Vector3.right * Input.GetAxis("Home2") * Time.deltaTime * moveSpeed); 
      transform.Translate(Vector3.up * Input.GetAxis("UpDown") * Time.deltaTime * moveSpeedUpDown); 
   }
}

Attach this script to all of your free moving cameras and it should work as long as you are still enabling and disabling your cameras.

Hi thankyou again for awnser MegadethRocks!!!

This is what happend!

MissingComponentException: There is no ‘Camera’ attached to the “Camera” game object, but a script is trying to access it.
You probably need to add a Camera to the game object “Camera”. Or your script needs to check if the component is attached before using it.

FlyCam1.Update () (at Assets\Scripts\Camera\FlyCam1.js:7)

I put your code there!
code:
function Update(){
if (camera.enabled)
{
transform.Rotate(Vector3.up * Input.GetAxis(“Mouse X”) * Time.deltaTime * sensitivity);
transform.Translate(Vector3.forward * Input.GetAxis(“Home”) * Time.deltaTime * moveSpeed);
transform.Translate(Vector3.right * Input.GetAxis(“Home2”) * Time.deltaTime * moveSpeed);
transform.Translate(Vector3.up * Input.GetAxis(“UpDown”) * Time.deltaTime * moveSpeedUpDown);
}
}
I can still switch camera from 1-5 key button but I can´t move anyone of them!
I even tryed this way too! But with this one I dident get any error message but I can still switch camera from 1-5 key button but I can´t move anyone of them!

code:
var sensitivity : float = .1;
var moveSpeed : float = 5;
var moveSpeedUpDown: float = 2;

function Update() {
transform.Rotate(Vector3.up * Input.GetAxis(“Mouse X”) * Time.deltaTime * sensitivity);
transform.Translate(Vector3.forward * Input.GetAxis(“Home”) * Time.deltaTime * moveSpeed);
transform.Translate(Vector3.right * Input.GetAxis(“Home2”) * Time.deltaTime * moveSpeed);
transform.Translate(Vector3.up * Input.GetAxis(“UpDown”) * Time.deltaTime * moveSpeedUpDown);

}
So what to do now?
Thankyou for your time!

Maybe some picture can help!

Maybe some picture can help!

Maybe some picture can help!

Maybe some picture can help!

The FlyCam script needs to be attached to the GameObject containing the Camera for this script to work. Since your Camera object is actually a child of the GameObject that your FlyCam script is attached to, it can’t find the Camera. A quick fix to this would be to add a public Camera variable to your FlyCam script. Then drag the child Camera object into the FlyCam script in the editor (These will be the same cameras you dragged into the CompassCam script). Then your Update function would look like this.

var cam : Camera;

function Update(){ 
   if (cam.enabled) 
   { 
      transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * Time.deltaTime * sensitivity); 
      transform.Translate(Vector3.forward * Input.GetAxis("Home") * Time.deltaTime * moveSpeed); 
      transform.Translate(Vector3.right * Input.GetAxis("Home2") * Time.deltaTime * moveSpeed); 
      transform.Translate(Vector3.up * Input.GetAxis("UpDown") * Time.deltaTime * moveSpeedUpDown); 
   } 
}

I would also suggest that you stick to one scripting language for simplicity. I noticed that your CompassCam is in C# and your FlyCam is in JS.

Yes It works!!!
Thankyou very much for your help!!!

I hope I can help you some day too with something other than scripting!

Thankyou for your time!!!

To early to be happy!
I open the project after saving this happend!
Now it seems that tha character is desible, he wont move then I switch to a free camera. In the Main Camera he is okej.

And he lost his ThirdPersonCamera to follow again!

dont know what to do?

I think is something with the Tag, I have test to change it to different tags for the free camera but nothing helps.
If the Main Camera have the Tag to MainCamera everyting works but in the free camera that are untagged the character stops play only in the Main Camera he is playing his moves!

If the Main Camera have the Tag to MainCamera and the free cameras have the Tags to MainCamera it works but the Main Camera loses the Third Person camera to follow.( Spring Follow Camera script).

If the Main Camera have the Tag to Untagged and the free cameras have the Tags to MainCamera it works but in the Main Camera the character is dead, no moves, he is disable and the Third Person camera too

I have try all the different ways I think, but I dont know what to do now?

It looks like the SpringFollowCamera script has no connection to the ThirdPersonController! It loses his connection, How can I force it to connect?

Maybe add somekind of variable like:
var Script = GameObject.AddComponent(ThirdPersonController);

But I dont know how to do it?
Somebody know how to do it?