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 kiwi koder · May 25, 2013 at 07:37 AM · colorguitexturepixel

Get color of pixel at mouse click of a GUITexture

I was wondering how you would get the color of the pixel that the mouse click on a GUITexture

Comment
Add comment · Show 2
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 Fattie · May 25, 2013 at 09:05 AM 0
Share

does this help ..

http://docs.unity3d.com/Documentation/ScriptReference/RaycastHit.html

http://docs.unity3d.com/Documentation/ScriptReference/RaycastHit-textureCoord.html

awesome, eh ?

avatar image kiwi koder · May 27, 2013 at 02:19 AM 0
Share

Does a GUITexture have a collider? I thought that Raycasts only work then there are colliders?

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by robertbu · May 28, 2013 at 02:08 PM

Here is a bit of code. Your texture must be marked as Read/Write enabled in the texture importer. Also The width and height in the Pixel Inset settings of the GUITexture must match the real width and height of the image:

 #pragma strict
 private var tex : Texture2D;
 private var v3Corner : Vector3;
 
 function Start () {
     var gt = GetComponent(GUITexture);                  
     tex = gt.texture;
     
     var v3Pos = Camera.main.ViewportToScreenPoint(transform.position);
     v3Corner = Vector3(v3Pos.x+gt.pixelInset.x, v3Pos.y+gt.pixelInset.y, 0.0);
 }
 
 function OnMouseDown() {
         var v3Pixel = Input.mousePosition - v3Corner;
         Debug.Log(tex.GetPixel(v3Pixel.x, v3Pixel.y));
 }
Comment
Add comment · Show 4 · 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 Zouaghi.HouSSeM · Mar 06, 2014 at 03:04 PM 0
Share

hello , thanks for the answer but how can i make it r/w ?

avatar image robertbu · Mar 06, 2014 at 03:23 PM 0
Share

Select the texture in the inspector. Change its type to 'Advanced', then turn on the Read/Write Enabled flag.

avatar image Zouaghi.HouSSeM · Mar 19, 2014 at 09:46 PM 0
Share

hello is was a wonderful solution but i want this code on c# and i cant covert this ligne to c#

 var gt = GetComponent(GUITexture);

            
 help !
avatar image robertbu · Mar 19, 2014 at 10:44 PM 0
Share

I wrote this code nearly a year ago and would do it differently today. Replace lines 6 and 7 with:

  tex = guiTexture.texture;

Just for information purposes, that line would be written in C# as:

  GUITexture gt = GetComponent<GUITexture>();
avatar image
0

Answer by PORUSH MANJHI · May 27, 2013 at 04:36 AM

you can download colorpicker from assetstore.

Comment
Add comment · Show 2 · 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 kiwi koder · May 28, 2013 at 09:58 AM 0
Share

This is in unity not chrome...

avatar image frogsbo · Jun 07, 2014 at 12:30 PM 0
Share

there is another question with an answer to that here on forums i jsut posted there just now. search my name and "screen.width" in google. its a magic treasure hunt, the net :D

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

15 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

Related Questions

Change colour of guiTexture from green to red. 1 Answer

How can I change all of a textures pixels to one color? 1 Answer

Material doesn't have a color property '_Color' 4 Answers

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

How to change a guiTexture color when a float is a certain number? 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