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 Frank Clark · Mar 22, 2011 at 01:53 PM · guitextureongui

OnGui Function help

Hello Will. Doubt you will reply but on the off chance. I am using function OnGui and need when an object is click for it to change the image in a texture. much like the tutorial above but a bit more advanced.

var tex1 : Texture2D; var tex2 : Texture2D;

function OnGui{

if(GUILayout.Buttin((tex1), GUILayout.width(119),GUILayout.Height(119))){ Destroy(GameObject.FindWithTag(bike)); Instantiate(bigWheel2, Vector3(13,13,-507),Quaternion.identity); guiTexture.texture = tex2;

}

}

However i get the following error message: MissingComponentException: There is no GUITexture attatched to the ramp game object, but a script is trying to access it. You probably need to add the GUITexture to the game object ramp or your script needs to check if the component is attatched before using it.

It is definatly attatched to ramp so i need to check if its attatched before using it. How do i do this? i have tried if statements like:

if(tex1){ guiTexture.texture = tex2; }

but that doesnt work. any ideas?

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 Kourosh · Mar 22, 2011 at 02:51 PM

error handling:

var tex1:Texture2D;

function OnGUI(){

if(tex1 != null){ <<------It should work. if(GUI.Button(Rect(10,10,100,20), tex1) //blah blah } else { Debug.Log ("Please assign the texture."); }

}

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 Frank Clark · Mar 22, 2011 at 03:07 PM 0
Share

i don't see how that could help :s

I need to swap the tex1 for tex2 when the gui button is clicked. so where it says

if(GUILayout.Button(tex1)),GUILayout.width(119),GUILayout.Height(119)))

i effectively need to write a script that changes that tex1 to tex2

avatar image Frank Clark · Mar 23, 2011 at 12:53 PM 0
Share

I have fixed the problem... all i need is a variable called currentTex then tell that variable what texture to have at what time. eg.

if(GUILayout.Button((currentTex2), GUILayout.Width(119), GUILayout.Height(119))){ if(scorer >= 20){ Debug.Log("You have enough money"); Destroy(GameObject.FindWithTag ("bike")); gameObject.Find("Score").GetComponent(score).theScore-=10; Instantiate(bigWheel2, Vector3(13.58261, 13.05622, -507.1505),Quaternion.identity); bigWheel = GameObject.FindWithTag("bike").transform; bigWheel.transform.rotation = Quaternion

avatar image Frank Clark · Mar 23, 2011 at 12:54 PM 0
Share

sorry what i meant was this:

if (GUILayout.Button((CurrentTex2), GUILayout.Width(119), GUILayout.Height(119))){

if(scorer>=20){ currentTex = tex2;

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

No one has followed this question yet.

Related Questions

Render GUI elements to off screen camera 1 Answer

Web player screen corruption 1 Answer

Change GUI.Button Texture on runtime 1 Answer

Making texture cover whole button 1 Answer

GUI.DrawTexture on GUI.Button press 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