I have been trying make a c# script that can change the cardboard camera to other cardboard camera, like when a character choose a chair, he teleport to cardboard camera on this chair:
Basically I just want switch cardboard camera for another cardboard camera.
This is c# script that I use:
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
public class teste1 : MonoBehaviour {
public GameObject[] CamInicial = new GameObject[59]; // inicialização da camera
public GameObject[] CamNext = new GameObject[59]; // camera para a qual se vai fazer switch
int n; // id da camera
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Physics.Raycast(transform.position, transform.forward, out hit))
{
if (CamNext[n] != null)
{
switchCameras(n);
}
}
}
private void switchCameras(int keyNum)
{
for (int i = 0; i < CamNext.Length + 1; i++)
{
if (CamNext *!= null && keyNum != i)*
{
// turn camera off
CamNext*.GetComponent().enabled = false;*
}
else {
// turn camera on
CamNext*.GetComponent().enabled = true;*
}
}
}
}
Console error:
Assets/Scripts/teste1.cs(22,72): error CS0103: The name `hit’ does not exist in the current context