I am making a driving game and i need help, switching the camera, how can you make it use a key
var MainCamera : GameObject = GMC;
var OverheadCam : GameObject = GMC;
var GMC : GameObject ;
function OnGUI () {
// Make a background box
GUI.Box (Rect (10,10,100,90), "Camera");
// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
if (GUI.Button (Rect (20,40,80,20), "Hood")) {
MainCamera.camera.active = false;
OverheadCam.active = true;
}
// Make the second button.
if (GUI.Button (Rect (20,70,80,20), "Main Camera")) {
MainCamera.camera.active = true;
OverheadCam.active = false;
}
}
thats what i have now, instead of a button, how do i use a Key like C?
i just used the weapon switch prefab from the unity tutorial series
function Start () {
// Select the first weapon
SelectWeapon(0);
}
function Update () {
// Did the user press fire?
if (Input.GetButton ("Fire1"))
BroadcastMessage("Fire");
if (Input.GetKeyDown("1")) {
SelectWeapon(0);
}
else if (Input.GetKeyDown("2")) {
SelectWeapon(1);
}
}
function SelectWeapon (index : int) {
for (var i=0;i<transform.childCount;i++) {
// Activate the selected weapon
if (i == index)
transform.GetChild(i).gameObject.SetActiveRecursively(true);
// Deactivate all other weapons
else
transform.GetChild(i).gameObject.SetActiveRecursively(false);
}
}
then you just drag the first cam in that is your first vieuw (press 1)
and you drag second cam in ; thirdperson vieuw (pres2)
here is a picture of howe it has to look like
but do notice that you need to copy your car as well
i am not a scipter i am just a newb that uses pre made scripts and modify them a bit
This variable will be visible in the inspector and you can set its values from there. With an array, you need to set the size property first (to the number of cameras you want) and then drag the individual camera objects to their slots.