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
1
Question by rct3fan24 · Nov 07, 2013 at 09:36 PM · colortrailrenderer

How do I change the color of a Trail Renderer by script?

In a game that I'm making, I have bullets with a Trail Renderer attached, so there's a white trail behind the bullet. What I'm trying to achieve is make it so the trail of the bullet turns orange when you use a power-up.

 function Update()
 {
     if(RatePowerup.powerActive == true)
     {
         //Change color of the bullet trail to orange
     } else 
     {
         //Change color back to white
     }
 }

This script is attached to the Bullet object. "powerActive" is a static variable in the script attached to the power-up. Can anyone help? Thanks!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by chaosmaker · Nov 08, 2013 at 01:03 AM

It is not possible to change the color of the Trail Renderer.

Workaround is:

Put an empty child game object under your bullet named "OrangeTrail" and attach a trail renderer with orange color to it and make the trailer renderer component disabled, then:

         if (RatePowerup.powerActive == true)
         {
             // Disable white trailer
             GetComponent<TrailRenderer>().enabled = false;
 
             // Enable orange trailer
             transform.Find("OrangeTrail").GetComponent<TrailRenderer>().enabled = true;
         }
         else
         {
             // Enable white trailer
             GetComponent<TrailRenderer>().enabled = true;
 
             // Disable orange trailer
             transform.Find("OrangeTrail").GetComponent<TrailRenderer>().enabled = false;
         }

So just toggling between two trailers is the solution.

Comment
Add comment · Show 5 · 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 rct3fan24 · Nov 08, 2013 at 02:06 AM 0
Share

I had to do some troubleshooting with this script, because some things produced a bunch of errors. For example, when you get components it should be just "GetComponent(TrailRenderer)". None of those angle brackets.

Thanks for the help, though! I'll mark this answer as correct anyways

avatar image Nuitari · Nov 26, 2013 at 12:39 PM 0
Share

This is wrong, the color can be changed. See my answer.

avatar image rct3fan24 · Nov 26, 2013 at 06:16 PM 0
Share

Hey, @Nuitari, I wouldn't say it's wrong, it's just slightly over complicated. Your answer is great, but I already have this working, and it's been working for a while. It's a little bit late to change it...

avatar image chaosmaker · Nov 26, 2013 at 06:22 PM 0
Share

Yeah it is right, you can have it tinted through material but it doesn't mean that you can access the color array of it (In case you want to have two unique trailers). See this post for more details:

http://forum.unity3d.com/threads/54162-Trail-Renderer-Colors-C

avatar image Nuitari · Nov 27, 2013 at 09:42 AM 0
Share

True, but the question wasn't about changing the color array, it was about making a white trail orange. Anyway, hope this helps other people with similar problems.

avatar image
6

Answer by Nuitari · Nov 26, 2013 at 10:31 AM

It is not true that the trail color cannot be changed. See here for a simple solution.

You have to give the trail object a material with shader Particles/Additive and then you can access the material's tint color in code:

 myTrail.material.SetColor("_TintColor", newColor);


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 imuniz · Aug 01, 2019 at 03:03 PM

Or you just create public Color variables and assign then to the TrailRenderer.startColor or .endColor.

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

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Trail renderer color always black 3 Answers

Is it possible to switch between trail color presets in code? 1 Answer

Changing tint color of skybox via script 2 Answers

Accessing and changing particle color in script 1 Answer

How can I change all of a textures pixels to one color? 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