Hello all,
I would like to create a colour-coded pick-up system whereby, on contact with any of said pick-ups, the player object changes colour (Red, Blue, Green) to match. The player will be required to change colour to be able to access doors or trigger switches only accessible when they are the appropriate colour (think something like Mercury Meltdown). If possible, I would also like a system implemented where, if the player contacts multiple colours in rapid succession (say, within ten seconds of one another), the colours fuse to create a new resultant colour (for example, red and blue will turn the player purple).
What would be an efficient method for going about doing this? If you need more details, feel free to ask.
Thanks in advance,
Chronozoah
You should create a script and put it on your character. It should look like this:
function OnCollisionEnter (collision : Collision) {
if(collision.gameObject.tag == "redObject")
renderer.material.color = Color.red;
if(collision.gameObject.tag == "blueObject")
renderer.material.color = Color.blue;
if(collision.gameObject.tag == "greenObject")
renderer.material.color = Color.green;
}
Just replace “redObject” and those other names with what your pickups are called. I hope this helped.
Unless you plan on 1000s of objects, efficiency should be an issue with the way you got thing setup. Here is a basic bit of code to change the color:
#pragma strict
function OnCollisionEnter(col : Collision) {
if (col.gameObject.tag == "ColorChanger") {
renderer.material.color = col.gameObject.renderer.material.color;
}
}
Creating an average color is a separate question and more complex You’ll have to store the colors and times of collision in some sort of a list. On collision, you will look through the list for any entries that are new enough and average the rgb values.