I am trying to make a script that lets me toggle between my first and third person camera but i get three errors error CS0029: Cannot implicitly convert type ‘bool’ to ‘cameratoggle’ CS0119: ‘Input.GetKeyDown(KeyCode)’ is a method, which is not valid in the given context CS1061: ‘bool’ does not contain a definition for ‘enabled’ and no accessible extension method ‘enabled’ accepting a first argument of type ‘bool’ could be found (are you missing a using directive or an assembly reference?)
Any help would be greatly appriciated, i am still very new to unity so i may not nderstand all of the terms yet.
using UnityEngine;
using System.Collections;
public class cameratoggle : MonoBehaviour
{
public cameratoggle fpsCamera;
public cameratoggle tpsCamera;
bool fpsCam = true;
// Use this for initialization
void Start()
{
fpsCamera.enabled = fpsCam;
tpsCamera = !fpsCam;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown.G)
fpsCam = !fpsCam;
fpsCam.enabled = fpsCam;
tpsCamera.enabled = !fpsCam;
}
}
}
if you even need that, I’m not sure what you’re trying to do there. fpsCam is a bool, and fpsCamera is the camera, which has a property .enabled. Bools don’t have that property.
If you did not write this code, just delete it, it’s horribly broken. Start afresh from a good new tutorial. There’s no value for anyone here to have you proxy-edit broken code that you think might do something but you’re not really sure.
To be honest, its the third tutorial i followed to try ad get it too work and it still hasnt worked so im not very sure how to get it to work, i just want the ability to toggle between my first and third person camera.
Looking closer at your code and the indentation whackiness, you have your Update() method inside your Start() method. Pull it out and make it a peer function to it, just another class function alongside Start(), just the way an empty script does. Don’t put any functions inside other functions. Unity cannot call function within functions.