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 28, 2013 at 08:32 AM · colorgetpixel

Compare getPixel() to a Color

I am needing to use the TextureMap.GetPixel() in a switch and case statement. There are several specific colors that the ray will definitely hit which is why I am trying to use a switch case statement. The several colors that will be hit are Color(0.925,0.942,1.000,1.000) and Color(0.000,0.941,1.000,1.000) for example. I have tryed

 var color = Color(0.925,0.942,1.000,1.000) 
 switch(TextureMap.GetPixel (pixelUV.x,pixelUV.y)){
     case color:
         print("This is southland");
         break;
 }
 //also doesn't work
 if(TextureMap.GetPixel (pixelUV.x,pixelUV.y) == color){
      print("This is southland");
 }

But this doesn't work even if when both color and getPixel() are printed and they are exactly the same. Also doesn't work in if statements. Can anyone see anything that is wrong with the code?

Comment
Add comment · Show 3
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 · Dec 02, 2013 at 08:55 AM 0
Share

Any reason for the down vote on this question?

avatar image MrVerdoux · Dec 02, 2013 at 09:03 AM 0
Share

I don´t see any so I up voted you to compensate it...

avatar image kiwi koder · Dec 02, 2013 at 09:06 AM 0
Share

Thank you @$$anonymous$$rVerdoux

1 Reply

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

Answer by numberkruncher · May 28, 2013 at 08:38 AM

Whilst not necessary, I would recommend defining your selection colours as constants for cleaner code, but essentially the following would work:

 // C#
 public static readonly Color FirstColour = new Color(0.925f, 0.942f, 1f, 1f);
 public static readonly Color SecondColour = new Color(0f, 0.941f, 1f, 1f);

 public void Foo(Texture2D tex) {
     Color pixel = tex.GetPixel(10, 10);

     if (pixel == FirstColour) {
         // ...
     }
     else if (pixel == SecondColour) {
         // ...
     }
 }

 // UnityScript
 public static var FirstColour:Color = new Color(0.925f, 0.942f, 1f, 1f);
 public static var SecondColour:Color = new Color(0f, 0.941f, 1f, 1f);

 public function Foo(tex:Texture2D) {
     var pixel:Color = tex.GetPixel(10, 10);

     if (pixel == FirstColour) {
         // ...
     }
     else if (pixel == SecondColour) {
         // ...
     }
 }
Comment
Add comment · 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

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

14 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

Related Questions

create readable colour map 1 Answer

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

Using GetPixel to instantiate blocks of different pixel colors 1 Answer

Changing two different objects renderer colour 1 Answer

How to pixelate an image texture for faster pixel color recognition? 2 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