Unity Color32



Unity

So, I scratched that idea then I tried to save.Write as image then render it in unity but Unity returns an error: Cannot implicitly convert type 'UnityEngine.Color32' to 'UnityEngine.Sprite' I tried using the answer from here where they used Sprite.Create as a solution but converted a Texture2D instead of a Color32 but I wasn't able. I have data coming in from a JSON file with a bunch of RGB strings in the format color: '255,255,255' - I want to colorize things in Unity by reading that string and converting it to a color32, but I can't figure out how to convert these to the format that Unity needs: new Color32(255,255,255,255).

Unity Color32 Lerp

A simple C# script that allows for creating UnityEngine Color32 variables via a hex code string

Getting Started

Color32

Getting ColorHex into your Unity project is as simple as dropping the ColorHex.cs file into your Assets/Scripts project folder.

Usage

In order to have access to ColorHex in your script, make sure to include using ColorHexUtility; at the top of any script that requires it.

Unity

Unity Color32 Vs Color

Instead of using Color32’s constructor which requires you to pass byte values, you can now use the ColorHex constructor to pass in a hex code string. Since ColorHex is designed to be interoperable with Color32, an implementation can look like this:

Features

  • Reduces development time (and headaches) by letting you use a color code that can be copy-pasted straight from programs like Photoshop
  • Works with or without a preceding ‘#’ character
  • Supports alpha values (ex. #FFFFFF00)
  • Allows some text editor/IDE plugins to preview your color (ex. Color Info for Visual Studio Code