Hi yes I am looking for help on a camera adaptation script I saw in the tutorial example
using UnityEngine;
using System.Collections;
public class MultipleCameras : MonoBehaviour {
public Camera firstPersonCamera;
public Camera thirdpersonCamera;
public Camera overheadCamera;
public Camera targetCamera;
public Camera targetCamera1;
public void ShowOverheadView() {
if(Input.GetKey(KeyCode.C) )
firstPersonCamera.enabled = false;
overheadCamera.enabled = true;
}
public void ThirdpersonView() {
firstPersonCamera.enabled = false;
thirdPersonCamera.enabled = true;
}
public void ShowFirstPersonView() {
firstPersonCamera.enabled = true;
overheadCamera.enabled = false;
}
public void TargetCameraView() {
if (Input.GetKey (KeyCode.T))
firstPersonCamera.enabled = false;
targetCamera.enabled = true;
}
public void TargetCameraView1() {
if (Input.GetKey (KeyCode.T))
targetCameraCamera.enabled = false;
targetCamera1.enabled = true;
}
}
But I keep getting this error : ‘‘the name______________does not exist in the current context’’ You see the idea is to have multiple camra’s in a scene that the player can see from like a an aircraft or a tank or another soldier or an an ariel drone or a nav point from thier 1st person view
None of those functions will be automatically called by Unity. All of them just flip cameras on and off. All of the so-called “heavy lifting” has to be somewhere else, either in your main character controller detecting that you fulfilled certain conditions, or processed user input, or changed vehicles or whatever.
Also, three of the five functions above, when called, check to see if the T or the C key is held down at that very instant, and then slightly modify what they turn on or off. I don’t think you’ll get very far with that script as it looks like it is part of a much larger project and also encodes a lot of that project’s core assumption.
I would recommend starting with something simple like an overhead camera that you can flip on and off with a key, overriding your first person camera, and get that working first. Any of the basic Unity object enable/disable tutorials will cover the basics for that.
Yeah thanks but any 1st/3rd person game would have what? A 1st person camera for looking around, 3rd person over the shoulder or behind camera a Sniper rifle camera and a camera permanently facing a minimap be it your using the ususual dynamic flat terrain or what I am interested in a spherical world map what I need is switches which would switch from 1st to 3rd to sniper which I envisage being clicked on by the right mouse button as an alternative sniper mode
Now the T mode cameras would be activated as the player hit T or use the a button on the joystick you could see from the FPS sight of the A.I I was thinking more that the button on the joystick just targets the A.I /A.I’s vehicle and the T on the keyboard is used to actually see from the A.I ;s FPS view I actually managed to get around or corrrect that error but still have to test this code to see that it works properly though I have debugged it and it seems clean
using UnityEngine;
using System.Collections;
public class MultipleCameras : MonoBehaviour {
public Camera firstPersonCamera;
public Camera thirdpersonCamera;
public Camera overheadCamera;
public Camera targetCamera;
public Camera targetCamera1;
public Camera targetCamera2;
public Camera targetCamera3;
public Camera targetCamera4;
public Camera targetCamera5;
public Camera targetCamera6;
public void ShowOverheadView() {
if(Input.GetKey(KeyCode.C))
firstPersonCamera.enabled = false;
overheadCamera.enabled = true;
}
public void ThirdpersonView() {
if(Input.GetKey(KeyCode.C))
firstPersonCamera.enabled = false;
thirdpersonCamera.enabled = true;
}
public void ShowFirstPersonView() {
if(Input.GetKey(KeyCode.C) )
firstPersonCamera.enabled = true;
overheadCamera.enabled = false;
}
public void TargetCameraView() {
if (Input.GetKey (KeyCode.T))
targetCamera.enabled = true;
targetCamera1.enabled = true;
targetCamera2.enabled = false;
targetCamera3.enabled = false;
targetCamera4.enabled = false;
targetCamera5.enabled = false;
targetCamera6.enabled = false;
}
public void TargetCameraView1() {
if (Input.GetKey (KeyCode.T))
targetCamera.enabled = false;
targetCamera1.enabled = true;
targetCamera2.enabled = false;
targetCamera3.enabled = false;
targetCamera4.enabled = false;
targetCamera5.enabled = false;
targetCamera6.enabled = false;
}
public void TargetCameraView2() {
if (Input.GetKey (KeyCode.T))
targetCamera.enabled = false;
targetCamera1.enabled = false;
targetCamera2.enabled = true;
targetCamera3.enabled = false;
targetCamera4.enabled = false;
targetCamera5.enabled = false;
targetCamera6.enabled = false;
}
public void TargetCameraView3() {
if (Input.GetKey (KeyCode.T))
targetCamera.enabled = false;
targetCamera1.enabled = false;
targetCamera2.enabled = false;
targetCamera3.enabled = true;
targetCamera4.enabled = false;
targetCamera5.enabled = false;
targetCamera5.enabled = false;
}
public void TargetCameraView4() {
if (Input.GetKey (KeyCode.T))
targetCamera.enabled = false;
targetCamera1.enabled = false;
targetCamera2.enabled = false;
targetCamera3.enabled = false;
targetCamera4.enabled = true;
targetCamera5.enabled = false;
targetCamera6.enabled = false;
}
public void TargetCameraView5() {
if (Input.GetKey (KeyCode.T))
targetCamera.enabled = false;
targetCamera1.enabled = false;
targetCamera2.enabled = false;
targetCamera3.enabled = false;
targetCamera4.enabled = false;
targetCamera5.enabled = true;
targetCamera6.enabled = false;
}
public void TargetCameraView6() {
if (Input.GetKey (KeyCode.T))
targetCamera.enabled = false;
targetCamera1.enabled = false;
targetCamera2.enabled = false;
targetCamera3.enabled = false;
targetCamera4.enabled = false;
targetCamera5.enabled = false;
targetCamera6.enabled = true;
}
}
I hope it works I had problems wth using the ‘else’ command