While researching to see if I could use colors other than the pre-defined ones for the Color component, I discovered that Unity can ‘implicitly convert’ between RGBa and Vector4 variables. This has allowed me to place the color selection process in the editor rather than the script (win for designers) and thus make it definable independently for each object/prefab.
using UnityEngine;
public class ObjectHit : MonoBehaviour
{
[Tooltip("'x'=Red, 'y'=Green, 'z'=Blue, 'w'=Alpha. All values must be enter between 0 and 1 (cv+1/256 where cv is the 'color component value')")]
[SerializeField] Vector4 hitColor = new Vector4();
private void OnCollisionEnter(Collision collision)
{
Debug.Log("I've been Hit by: " + collision);
ChangeColor();
}
void ChangeColor()
{
GetComponent<MeshRenderer>().material.color = hitColor;
}
}
as you can see though, due to the lack of ability to limit the components of the Vector4 to a single range, the RGBa values must be converted to a value between 0 and 1 (as opposed to 0 and 255).