Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by sarim987 · Feb 25, 2014 at 08:57 PM · errorbuttontouchguitexturecontext

"The name does not exist in the current context" error

Hi, for some reason i am getting this error and i don't really know how to deal with it. My gas and brake buttons are made by selecting it and creating other --> guiTexture. I did this though the unity program.

 foreach (Touch touch in Input.touches)
         {
             if (Gas.HitTest (touch.position)) 
             { 
                 Debug.Log("Clicked the button - Gas");
             } 
             else if (Brake.HitTest (touch.position)) 
             {
                 Debug.Log("Clicked the button - Brake");
             }
         }

CarMain.cs(96,29): error CS0103: The name Gas' does not exist in the current context*** ***CarMain.cs(100,34): error CS0103: The name Brake' does not exist in the current context

I am guessing i have to define Gas and Brake, but how would i do that if they are made through inspector. Any help would be appreciated.

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
0
Best Answer

Answer by brilliancenp · Feb 25, 2014 at 10:01 PM

Anything that you have brought into your project through the inspector that you would like to easily access in code , such as textures should be put in a folder named 'Resources' inside the root folder of your project. You can then access it like this:

GUITexture instance = (GUITexture)Resources.Load("Gas", GUITexture);

I believe this would be the correct syntax, but I have never used it for this type of resource. I do use this for sound files and such, I am not sitting at my Unity workstation but I believe this is correct. If not please comment and I will find the exact syntax.

On the other hand, if you want to access an object that you have put in your scene, you may want to access it using:

GameObject.find("Gas")

Where "Gas" is the name of the object in you scene.

Comment
Add comment · Show 3 · 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 sarim987 · Feb 25, 2014 at 10:23 PM 0
Share

I am getting this error. i put the files into the root resources folder. i am using c#

error CS0246: The type or namespace name `GuiTexture' could not be found. Are you missing a using directive or an assembly reference?

avatar image brilliancenp · Feb 25, 2014 at 10:26 PM 0
Share

I apologize, please use unity standard casing I believe 'GUITexture' ins$$anonymous$$d of 'GuiTexture' and please make sure the name "Gas" in quotes is the same casing as in the inspector.

I will update my original answer to reflect this.

I also realized that you may be trying to access an object in your active scene rather than just a resource in which case I updated the answer above

avatar image sarim987 · Feb 26, 2014 at 07:50 PM 1
Share

Thank you so much but i had to make a small edit

GUITexture instance = (GUITexture)Resources.Load("gas", typeof(GUITexture));

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

21 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

Related Questions

GUITexture OnMouseDown Problem 1 Answer

Can I assign controls to GUITexture button? 1 Answer

How to access other Scripts and Components 1 Answer

touch GUITexture Help 1 Answer

(Mobile) Touch anywhere on screen EXCEPT button 3 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