Question by
TKIZZLE · Dec 03, 2017 at 04:30 AM ·
playerscripting beginnerdebugcamerasclick objects
Switching Player's Camera By Clicking An Object
I've got five different cameras set up that are separate from the FPSCharacter camera the player starts with. The player is supposed to click on 1 of 5 different objects, and the camera switches from the FPScontroller to the camera corresponding to the objects. I can make it switch, the problem is that it goes to camera1 no matter where I click the game, even if I'm outside the room. When I click again it switches to camera5, and just back and forth with each click. So along with it not going to the correct camera according to the object I click on, I also need the player to stay in the camera view they chose.
Also, should I have this script on the objects or on the Player?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ClickSeat : MonoBehaviour {
public Camera camera1;
public Camera camera2;
public Camera camera3;
public Camera camera4;
public Camera camera5;
// Use this for initialization
void Start () {
camera1.enabled = true;
camera2.enabled = false;
camera3.enabled = false;
camera4.enabled = false;
camera5.enabled = false;
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0))
{
camera1.enabled = !camera1.enabled;
camera2.enabled = !camera2.enabled;
camera3.enabled = !camera3.enabled;
camera4.enabled = !camera4.enabled;
camera5.enabled = !camera5.enabled;
}
}
}
capture4.jpg
(36.8 kB)
capture3.jpg
(50.2 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612143845im_/https://answers.unity.com/themes/thub/images/avi.jpg)