- Home /
"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.
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.
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?
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
Thank you so much but i had to make a small edit
GUITexture instance = (GUITexture)Resources.Load("gas", typeof(GUITexture));
Your answer
 
 
             Follow this Question
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
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                