• 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
Question by justinkatic · Oct 11, 2017 at 05:15 AM · particlesnewbiecolouroncollisionchange material

Changing a material on a particle on collision

So basically I want to change the particles materials colour on my prefab when it hits the transform with tag Shield and I've tried just about everything I can think of but I cant seem to get at the right spot. here's my code at pretty much everything I have tried any help would be amazing hope I was at least somewhat close to solving somewhere. so in the image attached I want the green tint colour to be changed to lets say red on collision and only the one prefab that collided with the game object not all bullets turning red. any help would be absolutelyalt text amazing

 public Material myColor;
 public bool armed = false; // when true it will explode on impact
 void OnCollisionEnter (Collision col)
 {
     if (col.transform.tag == "Player") {
         Destroy (gameObject);
         // start explosion
         // decrement player health
     } else    if (col.transform.tag == "Shield") {
         armed = true;
         print ("armed " );

// print (GetComponentInChildren ().name); // ParticleSystem ps = GetComponentInChildren ();

         //Material pm = getcom GetComponentInChildren<Material> ();
         //print (pm.name);

// print (ps.GetComponent().material.GetColor("_TintColor").ToString()); // Renderer r = ps.GetComponent (); // r.material.SetColor ("_TintColor", new Color(1f,0f,0f,1f)); // print (ps.GetComponent().material.GetColor("_TintColor").ToString());

         //GetComponent<Renderer> ().material.SetColor("_TintColor", new Color(1f,0f,0f,1f));

         //Material[] m = ps.getcom ();
         //print ("mmmm " + m.Length);
         //print (GetComponentInChildren<ParticleSystem> ().GetComponent<MaterialPropertyBlock>());


         //gameObject.GetComponentInChildren<ParticleSystemRenderer>().material = newMat;


particle-snip.png (122.1 kB)
Comment
TBART82

People who like this

1 Show 1
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 MaxGuernseyIII · Oct 11, 2017 at 06:46 AM 0
Share

Please edit your question and more carefully format your code. You can use the "insert code" button (the icon for which is alternating ones and zeros), to do it pretty easily.

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by TBART82 · Oct 11, 2017 at 07:07 AM

You need to access the 'material' component in the 'ParticleSystemRenderer'. Here's a quick script I wrote up. This should do the trick!

 // The particle system you want to change
     public GameObject particle;
     // The new material you want to apply to the particle system
     public Material newMaterial;
 
     private void Start()
     {
         // Access the 'ParticleSystemRenderer' component, and change the material to 'newMaterial'.
         particle.GetComponent<ParticleSystemRenderer>().material = newMaterial;
     }
Comment

People who like this

0 Show 2 · 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 justinkatic · Oct 11, 2017 at 08:04 AM 0
Share

you are a CHAMPION :D!!!!

avatar image TBART82 justinkatic · Oct 11, 2017 at 09:26 AM 0
Share

Thanks! Keep programming and never give up!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

74 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 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 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 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 avatar image avatar image

Related Questions

Pong game collision problems 1 Answer

OnParticleCollision is broken 1 Answer

special fx on iphone 1 Answer

How do i make fire spread 1 Answer

Do large numbers of stopped particle systems hurt performance? 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