Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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.

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

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges