Posted on

How to Make a Color Picker in Unity

For this tutorial, I will show you how to create a color picker menu option in Unity. This will allow the players of your game to pick any color which can then be used for a number of different applications. You can have it change the color of an avatar’s clothes or hair. It could change the color of a car or a paintbrush like in Photoshop. The cool thing about this mechanic is that you don’t have to limit the players on what color they choose.

The way to create a color pick is that you first need to have a good texture 2D of a color wheel or pallet. If you need one you can download this Image.

You will then need to set up an event trigger on this image where you can take in the player’s mouse position. with this mouse position on this image, we can then get the pixel color at that position. Once you have the pixel color, you can use that color for whatever application you want.

ColorPickButton.cs

using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace InfoGamerHubAssets {

    public class ColorPickButton : MonoBehaviour
    {
        public UnityEvent<Color> ColorPickerEvent;

        [SerializeField] Texture2D colorChart;
        [SerializeField] GameObject chart;

        [SerializeField] RectTransform cursor;
        [SerializeField] Image button;
        [SerializeField] Image cursorColor;



        public void PickColor(BaseEventData data)
        {
            PointerEventData pointer = data as PointerEventData;

            cursor.position = pointer.position;

            Color pickedColor = colorChart.GetPixel((int)(cursor.localPosition.x * (colorChart.width / transform.GetChild(0).GetComponent<RectTransform>().rect.width)), (int)(cursor.localPosition.y * (colorChart.height / transform.GetChild(0).GetComponent<RectTransform>().rect.height)));
            button.color = pickedColor;
            cursorColor.color = pickedColor;
            ColorPickerEvent.Invoke(pickedColor);
        }
    }
}

DemoColorPicker.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace DmeoInfoGamerHubAssets
{
    public class DemoColorPicker : MonoBehaviour
    {
        public void SetColor(Color newColor)
        {
            GetComponent<MeshRenderer>().material.color = newColor;
            //Debug.Log(newColor);
        }
    }
}
Posted on

How to use Emission Maps in Blender and Unity

For this lesson, I will show you how to create an emission map and how to apply them to your models in Blender and Unity. An emission map is used to make parts of your model glow or give off light. In Unity, if you bake your static objects with emission materials it will cast light onto other static objects around it. You can also apply a bloom post-processing effect if you want to give your emission materials a halo effect.

Zombie Model: https://skfb.ly/6BKSF

Posted on

Unity – How to Create a Diablo 2 Monster – 3D to 2D Rasterization Pixel Art with Blender

For this Unity and Blender lesson, I show you how to take a 3D model and turn it into a 2D Rasterized sprite. This process has been used in many other video games such as Doom, Diablo, and Clash of Clans. This process is used to improve the optimation of your video game or as a way to stylize your game like pixel art.

Rasterization is most commonly used for games where you have a fixed camera. When you have a fixed camera the player is limited on how many different angles they can look at an object and when an object is only viewed from limited angles you might as well save some rendering power just go with some 2D sprites. You can tell an object has been rasterized if when you get close to the object or you zoom in on it and you can start to see the pixels of the 2D spite.

For a good lesson on how to make your rasterized images pixelated and look like pixel art, check out this blender tutorial.