c# - error CS0103: The name `hit' does not exist in the current context (cardboard switching)
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[i] != null && keyNum != i)
{
// turn camera off
CamNext[i].GetComponent<CardBoard>().enabled = false;
}
else {
// turn camera on
CamNext[i].GetComponent<CardBoard>().enabled = true;
}
}
}
}
Console error:
Assets/Scripts/teste1.cs(22,72): error CS0103: The name `hit' does not exist in the current context
Answer by mptp · Apr 15, 2016 at 02:21 PM
You need this line before your Raycast:
RaycastHit hit;
If you want to use the out hit version of Physics.Raycast.
However, it looks like you aren't using hit anyway, so you should omit the out hit parameter from your call to Physics.Raycast
Indeed, if you dont use the hit information omitting it from the Rasycast will result in a faster Raycast, as the hit information doesnt get populated.
Let me ask you a thing, this script than I create, can I switch a cardboard camera with that ?
Thank you, for your help. Cumpz!
Your answer
Follow this Question
Related Questions
Object appears to glitch as it moves whenever the camera follows it. 0 Answers
Making a pivot focused game 0 Answers
Needing help with 3rd person mouse camera 1 Answer
ScreenToWorldPoint not working 1 Answer
Navigation in VR Mode?!! 0 Answers