Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 SMM11 · May 10, 2016 at 03:45 PM · collisioncolor change

Change color on collision and keep track?

So, I'm making a 3D platform based on the idea of color. The platforms are all white until you land on them, and the object of the game is to change every platform from white to some random color before going to the exit. Is there a script that could make platforms change to a random color on collision, as well as keep track of which platforms you've landed on so it doesn't give you points for landing on platforms you've already gotten points for.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by fabian-mkv · May 10, 2016 at 05:02 PM

This is a pretty broad question, so I'll give a broad answer:

1) Create the platforms.

2) Add a Rigidbody component in the inspector so that your player can collide with it. Make sure to disable gravity (you don't want the platform falling with gravity) and enable "Is Kinematic" (you don't want it to move when a player lands on it).

3) You'll need to create a script and attach it to each platform. Let's name this script Platform. In the Platform script, next to Start() and Update(), add the function OnCollisionEnter as in the example given in the linked documentation. This function gets called whenever something collides with it (e.g.: player lands on it). Have it change color in that function using:

 GetComponent<MeshRenderer>().material.color = new Color(1f, 0f, 0f, 1f);

This should be enough to get you going. Read/Watch tutorials to learn more.

Comment
Add comment · Show 3 · 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 SMM11 · May 10, 2016 at 06:14 PM 0
Share

I only needed the script, I know about OnCollisionEnter and such, but thank you anyways, I appreciate it!

avatar image fabian-mkv SMM11 · May 10, 2016 at 06:31 PM 0
Share

I wasn't sure exactly what you were asking for, so I assumed that you were very new. If you'd like a random color, then create a script with the following:

 void OnCollisionEnter(Collision collision) {
   GetComponent<$$anonymous$$eshRenderer>().material.color = new Color(Random.value, Random.value, Random.value, 1f);
 }

Is that what you're looking for?

avatar image SMM11 fabian-mkv · Jun 02, 2016 at 03:15 PM 0
Share

Sorry for the delayed response, my notifications weren't working. It doesn't work, unfortunately. I attached it to the platforms as directed, but it actually changed the player's color, or at least it tried to. However, the player doesn't have a mesh to render because it's a first person game.

EDIT: Never $$anonymous$$d, it does work. It's just incredibly inconsistent.

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

How to change colors in turn? 1 Answer

Make something change color for a set amount of time 3 Answers

How do I change the color of a gameobject based on number of collisions? 1 Answer

How to change the color of the ball after hitting square? 5 Answers

How do I stop characters from standing on top of each other 1 Answer


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