• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by soeiromass · Apr 15, 2016 at 12:11 PM · c#camerascripting problemvrscript error

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image meat5000 ♦ · Apr 15, 2016 at 02:26 PM 1
Share

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.

avatar image soeiromass · Apr 15, 2016 at 08:17 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

156 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Switch between 5 cameras in the game by clicking. 0 Answers

How do I offset a camera when it's position is defined by a VR controller 0 Answers

load scene after video ended 2 Answers

How do I make the character rotate with the 2D camera? 0 Answers

Problems with rotation after zoom (camera like Sketchfab) 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges