I am trying to create a system where the player selects a color and clicks on a paint pallet to start mixing colors, the new color can be used to paint the environment. I have created these paintballs the player uses on the pallet but whenever they do the pallet simply changes from white to whatever color has been selected. This would be fine if it didn’t continue with every new color, basically if you try to add red to green it won’t become some mix it will simply become pure green. I am pasting my code down below and would greatly appreciate if anyone has any ideas on what to do to fix this. Id like to note that the preview being referenced in the scripts is simply a painted sphere in the players UI that lets them know what color they have.
.
Pallet Script
public class Pallet : MonoBehaviour {
public Color _color;
// Use this for initialization
void Start ()
{
_color = GetComponent<Renderer>().material.color;
}
public void MixPallet(Color color)
{
Color m_color = ((_color / 2) * (color / 2));
GetComponent<Renderer>().material.color = m_color;
Debug.Log(_color + " has been set the color");
}
}
.
Script that attempts to mix the paints
public class Casting : MonoBehaviour {
int range = 100;
public GameObject preview;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if (Input.GetButtonDown("Fire1"))
{
Debug.Log("Clicked");
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Vector3 rayOrigin = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f));
RaycastHit hit;
if (Physics.Raycast(rayOrigin, Camera.main.transform.forward, out hit, range))
{
Debug.Log("RayCast");
PaintBall _color = hit.collider.GetComponent<PaintBall>();
if (_color)
{
Debug.Log("Paintball has been selected");
preview.GetComponent<PaintPreview>().SetColor();
preview.GetComponent<Renderer>().material.color = _color.color;
}
Pallet _pallet = hit.collider.GetComponent<Pallet>();
if (_pallet)
{
Debug.Log("Pallet has been selected");
preview.GetComponent<PaintPreview>().hasPaint = false;
_pallet.MixPallet(preview.GetComponent<Renderer>().material.color);
}
}
}
}
}