- Home /
Question by
unity_999982324804EA8288AB · Feb 14 at 10:01 AM ·
c#cameratoggle
Toggling camera with one key,Toggle Camera with one key?
Hello guys , i'm new to Unity , I've been trying to toggle the camera with one key , it only toggle once , please help so i can understand what i'm missing in the script thanks a lot
//General Variables
public GameObject player;
private Vector3 offSet = new Vector3(0, 5, -7);
// View Cam Switch Variables (fCam"First Person View" tCam"Third Person View")
public KeyCode key;
public KeyCode key1;
public Camera fCam, tCam;
public bool camSwitch = true;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void LateUpdate()
{
//General Cam Position
transform.position = player.transform.position + offSet;
//Cam Switch between FirstView and ThirdView
if (Input.GetKeyDown(key))
{
camSwitch = !camSwitch;
fCam.gameObject.SetActive(camSwitch);
tCam.gameObject.SetActive(!camSwitch);
}
}
Comment
Answer by SellPet · Feb 14 at 12:45 PM
change if statement to this
if(Input.GetKeyDown(Key) && camSwitch){
camSwitch = !camSwitch;
// and change to third or first
}
else if(Input.GetKeyDown(Key) && !camSwitch){
camSwitch = !camSwitch;
// and change to third or first
}
I always do like this.
Your answer
Follow this Question
Related Questions
How can I create a toggle between an Unlocked and Locked camera? 0 Answers
Toggle between scripts with a script? 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers