- Home /
How do I convert pixel colours to numbers?
I want to create a level creator for my game but I can't figure out how I will set it so the game will read the image file and then convert each pixels colour as a number.
I've got a script that creates objects from numbers it's just the colour to number/text format that I can't figure out.
the game will read the colour file
You mean an image?
You can get the pixel color in an image with Texture.GetPixels(x,y,w,h);
Color[] temp = myTexture.GetPixels(x,y,w,h);
Then you'll just have to create a system to match a color to a number how ever you want to do it.
You are not giving too much details in your question...
Basically what I mean is I would draw an image up and then unity would read the image and convert each colour into a specific number in something like a text file, so if unity read a blue pixel it would export a 1 into a text file, then if it read yellow it would export 2 into a text file
Sorry for not giving that much detail
$$anonymous$$y script takes numbers and instantiates blocks at the same position as the number is in the text file and from what I know the way I've done it won't work with colours and I can't figure out a way to get it working with colours
Answer by PvTGreg · Dec 09, 2014 at 02:50 PM
http://answers.unity3d.com/questions/798859/randomly-generateplace-map-peices.html this is from one of my questions a while back maybe it is of some use
Answer by NoseKills · Dec 09, 2014 at 11:57 AM
Texture.GetPixels()
can be used for your purpose. Assign the image to a variable of type Texture in the inspector. Use GetPixels()
to read the pixel colors. Then you'll just have to make the conversion to number if (pixelColor == Color.white){...}
Your answer
Follow this Question
Related Questions
how do i store a really big number? 2 Answers
Turn numlock on at start 2 Answers
Golf swinging gauge - Techanically any type of recepricating gauge. 0 Answers
Large number of objects problem 1 Answer
Random gen script giving same numbers 3 times in a row 3 Answers