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 /
  • Help Room /
avatar image
0
Question by crimelinegames · Mar 18, 2017 at 09:13 PM · particlesoncollisionenter

Check Color of colliding particle?

I want to make a top down space shooter. The bullets are particle.

On my Enemy Class i have made this:

     void OnParticleCollision(GameObject other) {
             life--;
             if (life <= 0) {
                 Destroy(gameObject);
             }
         }

This working perfect. But one of my mechanic in this game is, to shoot bullets with different color. So the player can switch his bullet color.

Some Enemys are resisdent against a specific color. So I must check in the OnParticleCollision() which color the colliding Particle have.

 void OnParticleCollision(GameObject other) {
         life--;
         //Check here which Color this Particle have
         //<--- insert code
         if (life <= 0) {
             Destroy(gameObject);
         }
     }

Does somebody has any idea?

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
1
Best Answer

Answer by Mine54i__ · Mar 18, 2017 at 10:17 PM

     void OnParticleCollision(GameObject other)
     {
         life--;
         //Check here which Color this Particle have
         if (other.GetComponent<Renderer>().material.color == /* color here */)
         {
 
         }
         if (life <= 0)
         {
             Destroy(gameObject);
         }
     }


You will then input the color of the particle that you want detected. You would input something like Color.red, but make sure that if you do that, that the color that you have the particle is exactly the color you input, like Color.red, the particle color needs to be R: 255, B: 0 G: 0. I have not tried this yet, but it should work :)

Comment
Add comment · Show 4 · 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 crimelinegames · Mar 18, 2017 at 10:35 PM 0
Share

Thanks, but Unity give me this error: $$anonymous$$aterial doesn't have a color property '_Color' UnityEngine.$$anonymous$$aterial:get_color()

avatar image crimelinegames · Mar 18, 2017 at 10:49 PM 0
Share

Ok I changed the Particle $$anonymous$$aterial from "Default-Particle" to "Sprites-Default" and now there is no error. But now it returns 1,1,1. I think this is the color of the Sprite $$anonymous$$aterial without the color of the ParticleSystem :S

avatar image Mine54i__ · Mar 19, 2017 at 12:15 AM 1
Share

Hey! Sorry that I could not respond quicker, I had something going on. I think I figured it out. Is the color you set in the particle the start color? Or is it something else. If it is the start color that you set, this code will work.

         if (GetComponent<ParticleSystem>().main.startColor.color == Color.red)
         {
             //Do the stuff here
 
 
         }



That will detect what the start color is on the particle system. If you want to detect it on the collided object, you would change it to this.

         if (other.GetComponent<ParticleSystem>().main.startColor.color == Color.red)
         {
             //code here
 
 
         }

Other being the object that has the particle on it. Hope this helps! I tried it out and it works for me, but if it is not the start color that you set I will be happy to help you for whatever you have. If it is not the start color, if you could put the code of where you set the color or something that would be appreciated, then we could try and figure it out from there :)

avatar image crimelinegames · Mar 19, 2017 at 08:50 AM 0
Share

Thanks a lot. This works great. ;)

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

97 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 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

Having Player light torches Using Particle System and OnCollisionEnter? 1 Answer

Importing a blender mesh for a particle emitter. 3 Answers

optimize thousands of sprite prefab 0 Answers

How do you use emission.rate? 2 Answers

Particle Effect appears low-quality in-game. 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