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 TheGeekyDead · Dec 06, 2013 at 07:49 PM · texturesupportcs0117

Having issues with C# flashlight script (CS0117:)

Before i updated this morning it was working as intended, but i want to display an image in the upper left of the screen. Basic image letting the player know FLash light Off(Gray Out) and Flashlight Active(Full colored).

I created the images already, but i cannot seem to get it to let me add them, i am used to the java now so if anyone can point out what i "Fubar'ed" i would appreciate it.

Error: CS0117: UnityEngine.GUI' does not contain a definition for Texture' I forgot to note: It's on Lines, 45,48,49

Here is the code, i tried several variations, like toggle it On/Off, and jusr turn one of and the other off...

 using UnityEngine;
 using System.Collections;
 
 public class FlashLight : MonoBehaviour
 {
     public Texture2D image;
     public Texture2D image2;
     public Light FlashLightObject;
     private bool LightEnabled = false;
     private bool ShowHide = true;
 private bool ShowHide2 = false;
     
     void Update ()
     {
         if(Input.GetButtonDown("Flashlight"))
         {
             LightEnabled = !LightEnabled;
             FlashLightObject.enabled = LightEnabled;
             ShowHide = GUI.Texture (new Rect (10,10,image.width,image.height),image);
             //ShowHide.SetActiveRecursively(!ShowHide.active);
             audio.Play();
             if(!LightEnabled = false){
                  ShowHide2 = GUI.Texture (new Rect (10,10,image2.width,image2.height),image2);
                 //ShowHide2.SetActiveRecursively(!ShowHide2.active);
             }
         }
     }
 }
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

Answer by zombience · Dec 06, 2013 at 08:00 PM

Updated ah, you probably want to use a GUITexture then. http://docs.unity3d.com/Documentation/ScriptReference/GUITexture.html

 void Update()
 {
  // non gui stuff
 }
 
 void OnGUI()
 {
  // all your gui stuff
 }

Original you seem to be reassigning your boolean value LightEnabled. I wonder if this is causing your script to always evaluate it to false?

 if(!LightEnabled = false) // right here is a problem
 {
     ShowHide2 = GUI.Texture (new Rect(10,10,image2.width,image2.height),image2);
   //ShowHide2.SetActiveRecursively(!ShowHide2.active);
 }


you actually don't need to compare the boolean to false. you can just evaluate the bool, like so:

     if(!LightEnabled)
     { 
        // do stuff 
     }
Comment
Add comment · Show 12 · 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 zombience · Dec 06, 2013 at 08:00 PM 0
Share

to clarify, you intended to write:

 if(!LightEnabled == false)
avatar image TheGeekyDead · Dec 06, 2013 at 08:16 PM 0
Share

I fixed that, but the issue is it jkeeps saying:

(45,16): error CS0117: UnityEngine.GUI' does not contain a definition for Texture'

avatar image zombience · Dec 06, 2013 at 08:27 PM 0
Share

updated. check out GUITexture

avatar image TheGeekyDead · Dec 06, 2013 at 08:51 PM 0
Share

Ok i updated it, -GUI.Texture to GUITexture, now that error is gone but now it says...

CS0119: Expression denotes a type', where a variable', value' or method group' was expected

This is annoying, i don't know what i need to change now.

avatar image zombience · Dec 06, 2013 at 10:54 PM 1
Share

i believe you need to move your GUI calls into OnGUI()

for example:

 void Update()
 {
  // non gui stuff
 }
 
 void OnGUI()
 {
  // all your gui stuff
 }

OnGUI is a method that unity uses to process gui calls on gameobjects. you can use it like update, but put all of your GUI work in there. try that. if that isn't working for you, you should consider using GUITexture on a separate game object, and link that to your current script. then you can access it's texture via: GUITexture.texture

Show more comments

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

17 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

Related Questions

Assigning UV Map to model at runtime 0 Answers

Terrain texture low quality 0 Answers

Memory issues when taking Screenshots ? 1 Answer

rotate a texture inside a cube 1 Answer

Stuck at "Import EntityScene" 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