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
1
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
Add comment · 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
0
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
Add comment · 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 CHA$$anonymous$$PION :D!!!!

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

Thanks! $$anonymous$$eep program$$anonymous$$g 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.

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

A little problem in partciles 2 Answers

Particles/Multiply (Double) shader with shadows 0 Answers

Moving individual particles? 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