- Home /
Colour-based Pick-up System
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've given us very little information about your app.
2D or 3D?
Character controller, Rigidbody or Transform for movement?
Is contact mean a Collider, Trigger, mouse click, or finger tap?
$$anonymous$$aterial color, different textures, or vertex colors to set the color of your objects?
3D, top-down perspective.
Currently rigidbody is being used, but I would prefer to use whatever is most efficient.
Contact means when objects collide with one another, but I would prefer to use whatever is most efficient.
$$anonymous$$aterial colour, but I would prefer to use whatever is most efficient.
Answer by galika1080 · Nov 10, 2014 at 11:13 PM
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.
Answer by robertbu · Nov 10, 2014 at 11:16 PM
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.
Your answer
Follow this Question
Related Questions
object instances 0 Answers
How to change colour of objects? 1 Answer
Inventory System: "The given key was not present in the dictionary." 2 Answers
Particle Emitter starts when I have an object 1 Answer
inventory system issues 0 Answers