Hello i am new to Untiy 3D and coding within in Unity 3D :twisted:
I was woundering if you could help correct this code or tell me why i am unable to get it to work. :?:
I am wanting to switch between cameras which are located in the Hierarchy?
function Update() {
if (Input.GetButton ("e")){
{
Human_Camera.enabled(false);
Car_Camera.enabled(true);
}
}
if (Input.GetButton ("r")){
{
Human_Camera.enabled(true);
Car_Camera.enabled(false);
}
}
Thanks for your time!
JRavey
2
Does this script component know what Human_Camera and Car_Camera are?
Their presence in the hierarchy doesn’t mean much if you haven’t somehow linked them.
So would i create a empty GameObject and put the Human_Camera and Car_Camera inside the GameObject in the Hierarchy?
then change the script to
var Human_Camera : Camera;
var Car_Camera : Camera;
function Update() {
if (Input.GetButton ("e")){
{
Human_Camera.enabled(false);
Car_Camera.enabled(true);
}
}
if (Input.GetButton ("r")){
{
Human_Camera.enabled(true);
Car_Camera.enabled(false);
}
}
and then attatch the code to the GameObject?[/quote]
[/code]
You don’t need to parent the cameras to the game object (although you can if you like); otherwise, yes.
JRavey
5
Yes, that is it. Sorry for not replying sooner to close this out, I was out at dinner.