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 Ian-McCleary · Jun 18, 2015 at 08:53 PM · guierrortextureapi

Compnent.guiTexture is obsolete

I have just reopened an old project from Unity 4, and recieved quite a few errors in Unity 5. It is my play button, and even trying to use GetComponent() doesnt seem to fix it. here are the errors.

Assets/Scripts/PlayButton.js(11,9): BCE0144: 'UnityEngine.Component.guiTexture' is obsolete. Property guiTexture has been deprecated. Use GetComponent() instead. (UnityUpgradable)

Assets/Scripts/PlayButton.js(11,20): BCE0019: 'texture' is not a member of 'UnityEngine.Component'.

Assets/Scripts/PlayButton.js(16,9): BCE0144: 'UnityEngine.Component.guiTexture' is obsolete. Property guiTexture has been deprecated. Use GetComponent() instead. (UnityUpgradable)

Assets/Scripts/PlayButton.js(16,20): BCE0019: 'texture' is not a member of 'UnityEngine.Component'.

Here is my simple script, How can i fix the errors?

 #pragma strict
 var playNormal : Texture2D;
 var playHover : Texture2D;
 
 function Start () {
 
 }
 
 function OnMouseEnter ()
 {
     guiTexture.texture = playHover;
 }
 
 function OnMouseExit ()
 {
     guiTexture.texture = playNormal;
 }
 
 function OnMouseDown ()
 {
     Application.LoadLevel("spawned");
 }
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 Xarbrough · Jun 18, 2015 at 09:04 PM

 using UnityEngine;
 
 [RequireComponent(typeof(GUITexture))]
 public class TestScript : MonoBehaviour
 {
     public Texture2D playNormal;
     public Texture2D playHover;
 
     private new GUITexture guiTexture;
 
     void Start () 
     {
         guiTexture = GetComponent<GUITexture>();
     }
 
     // Rest of your code.
 }
 

Use this code. It will automatically add a GUITexture component to your GameObject if there is none. Then it creates a variable for the GUITexture. In past years, there was an automatic property for this, but since the GUITexture and old OnGUI System is being replaced by the new Unity UI, the properties are becoming obsolete. If you really need that component for some reason, use my code. The "new" keyword will override the inherited (but obsolete) property "guiTexture". It is still in Unitys codebase for documentation and to give instruction on how to make old project compatible.

Other than that, I would advise to look at the brand new UI System, which is very powerful: Unity official tutorials - UI

PS: Also, if you're using the old GUITexture component, the image you feed into it, must be marked as "Legacy GUI" I believe.

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 Ian-McCleary · Jun 18, 2015 at 10:56 PM 0
Share

This is great, except im not fluent in C# so im not exactly sure how i would do this. I dont understand why you wouldnt just call the 2 textures and not the private one.

avatar image Xarbrough · Jun 18, 2015 at 11:20 PM 0
Share

Texture2D is just an image. Nothing happens to it. GUITexture is a component which renders (displays) a Texture2D in the scene. That is what you've been doing already. You get the component called guiTexture and assign to its texture-property the playNormal texture. You can make those variables public, so that you can actually put int a Texture via the inspector field.

avatar image Ian-McCleary · Jun 18, 2015 at 11:27 PM 0
Share

Oh okay that makes sense, I solved it by using the updated UI system you recommended. I just used a button ins$$anonymous$$d of a texture. Thanks!

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

23 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

Related Questions

Wearied Error 1 Answer

Issue with Drawing a GUI texture 0 Answers

GUI Texture error. 1 Answer

Rotate Texture 1 Answer

Problem With GUI Circle Thickness 1 Answer


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