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 Gary Jackson · Mar 20, 2011 at 10:22 AM · colorgetcomponentguitextureguistyle

Transferring Color from script on another GameObject to a GUI.Box

Having had a good poke around...

I am trying to transfer a Color from a variable (ColorUnderCharacter) in a script (DataField) on another GameObject (dataField1,dataField2,n) to a GUI.Box.

And I have got this far with the basic script.

FYI; Ultimately, I am looking to see a GUI box displaying separated R,G & B colour values (0-255) for each of the ColorUnderCharacter Colors for each of the dataField1,n Objects.

Develops on previous SUCCESS: http://answers.unity3d.com/questions/45454/extracting-rgb-component-data-from-a-textured-plane-positioned-below-a-3d-terrain (Thanks to YoYo)

Where I think that there are Syntax Errors, I have marked the //<>

//read the base texture for GUI background (actually 32,32 Color.white) var plainTex : Texture2D ;

//creates a style for the GUI.Box var colorStyle : GUIStyle ;

//variable to store data from (GameObject.dataField1.DataField script) var rayTexColor : Color = Color.white ;

//Will be a Search string <<THINK: could use Array when reading multiple GameObject.dataField1 & dataField2 etc objects>> var gameObjectName : GameObject;

function OnGUI () {

 if(!plainTex){
     Debug.LogError("Missing Texture File") ;
 }

 if (!gameObjectName){
     Debug.LogError("No GameObject Listed") ;
 }

 //Find dataField data and set it to the current colour to paint the GUI
 GameObject.Find(gameObjectName).GetComponent.DataField.ColorUnderCharacter = rayTexColor ; //&lt;&lt;SYNTAX ERROR??&gt;&gt;
 print(rayTexColor.grayscale) ;

 //Configure the Box
 GUILayout.Box(plainTex) ;
 GUIStyle.normal.background = rayTexColor ; //&lt;&lt;SYNTAX ERROR??&gt;&gt;

 //Draw the Box
 GUI.Box(Rect(200,200,200,200), gameObjectName, colorStyle) ;

}

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

Answer by Jake-L · Mar 20, 2011 at 12:44 PM

You'll need to use GUI.backgroundColor:

Color c=GUI.backgroundColor
GUI.backgroundColor = rayTexColor;
GUI.Box(...) // this will be drawn using GUI.backgroundColor
GUI.backgroundColor = c;

Jake

Comment
Add comment · Show 1 · 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 Gary Jackson · Mar 21, 2011 at 12:44 AM 0
Share

Thank you. will do. much appreciated. Let me give it a go. I'm sure its the answer...

G

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

NullReferenceException when using GUIStyle to change text color 1 Answer

How to change a guiTexture color when a float is a certain number? 1 Answer

Change colour of guiTexture from green to red. 1 Answer

Can't create orange label 3 Answers

Material doesn't have a color property '_Color' 4 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