Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Chronozoah · Nov 10, 2014 at 08:53 PM · objectsystemcolourpick-up

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

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Nov 10, 2014 at 09:00 PM 0
Share

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?

avatar image Chronozoah · Nov 10, 2014 at 10:54 PM 0
Share
  • 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.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Wiki

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges