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 Igobackdoor · Oct 27, 2014 at 05:15 PM · not-working

Level Color Map

I'm trying to create a basic level from a image I created in paint. The script is trying to get each pixel and check its color and compare it to the color I have specified, but it doesn't seem to ever pass through the if statement. var img : Texture2D; var grass : GameObject;

 function Start () {
     for(var x : int = 0; x < img.width; x++) {
         for(var y : int = 0; y < img.height; y++) {
             Debug.Log(img.GetPixel(x,y));
             if(img.GetPixel(x,y) == Color(0.290, 1.000, 0.000, 1.000)) {
                 Debug.Log("working");
                 Instantiate(grass, Vector3(x, 0, y), Quaternion.identity);
             }
         }
     }
 }

The only thing I get in the Console is:(Well acctually 256 times since it's a 16x16 img) <\br><\br> RGBA(0.290, 1.000, 0.000, 1.000)<\br> UnityEngine.Debug:Log(Object)<\br> Level:Start() (at Assets/Scripts/Level.js:10)<\br>

which I got from the <\br> Debug.Log(img.GetPixel(x,y));

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
Best Answer

Answer by tanoshimi · Oct 27, 2014 at 08:48 PM

I don't see anything wrong with your code as such - I suspect that the problem comes from rounding errors in the color component values (i.e. the Red component of your pixels is not exactly equal to 0.290 - that's just the truncated value displayed by Debug.Log). As a result, your if condition is never evaluating to true.

Try it with a different image that only has white and black pixels and test for Color(0,0,0,1) and Color(1,1,1,1) - that should work.

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 Igobackdoor · Oct 27, 2014 at 08:55 PM 0
Share

Yea thanks, this worked. I'm not used to dealing with unity's Colors, I usually go with hexadecimals so that was the mistake.

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

2 People are following this question.

avatar image avatar image

Related Questions

Multiple Trigger Script doenst works! 1 Answer

Audio Streaming Not Working 1 Answer

help to add more details to my project 1 Answer

Why won't my character register as near? 2 Answers

Game dont work on Zenfone 5 0 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