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 jfn73150 · Aug 21, 2018 at 07:52 PM · if-statementsdamageparticle collision

[SOLVED]Different levels of damage per particle collision

I have a mech unit that shoots out 4 different particles that are set with collisions in order to damage an enemy. How do I code in 4 different levels of damage, one for each particle effect. I know how to make all particles do only one level of damage.
My code that you see here does not work. If I shoot the enemy with either 4 of the weapons the robot catches fire which is not intended. It should only catch fire when being hit by flameHitL or flameHitR.
My script does NOT work to change damages. It seems to add on the damages such in a way that the first if statement (shooting the enemy with the flameHitLR does its damage PLUS the damage of the rest of the if statements. (so 1 + 20 + 5) and kills the enemy instantly. The rest of the weapons don't seem to do any damage and they still set the enemy on fire. This script is on the enemy. Please take a look and see what I am doing wrong. I probably don't understand how the if statement work with collisions in this way.

     [SerializeField] int hitPoints = 100; //how many hitpoints of life the enemy has
 
     [SerializeField] Collider collisionMesh; //enemy's collider
 
     [SerializeField] ParticleSystem robotFlames; //particles that play when enemy is hit with flamesHitL or flamesHitR ONLY
 
     [SerializeField] ParticleSystem deathExplode;//particle system that plays when the robot runs out of hitpoints (death explosion)
 
 
     [SerializeField] ParticleSystem flameHitL; //    |
     [SerializeField] ParticleSystem flameHitR; //    |     
     [SerializeField] ParticleSystem bigGunHitL; //   Different types of particles each having a left and right
     [SerializeField] ParticleSystem bigGunHitR;//    |
     [SerializeField] ParticleSystem shotGunHitL;//   |
     [SerializeField] ParticleSystem shotGunHitR;//   | 
     [SerializeField] ParticleSystem grenadeExplosion;// grenade explosion particles 
 
     
     void OnParticleCollision(GameObject other)
     {
         // asking if the enemy is being hit by either flamehitL or flamehitR the hit damage should be 1 per particle collsion
 
         if (flameHitR || flameHitL) 
         {
             hitPoints = hitPoints - 1;
             robotFlames.Play(); // flamethrower hits enemy... enemy should catch on fire.
         }
 
         // asking if the enemy is being hit by either bigGunHitL or bigGunHitR the hit damage should be 20 per particle collsion
 
         if (bigGunHitL || bigGunHitR) 
         {
             hitPoints = hitPoints - 20; // enemies should NOT catch fire when being hit by normal bullets.
         }
 
         // asking if the enemy is being hit by either shotGunHitL or shotGunHitR the hit damage should be 5 per particle collsion 
 
         if (shotGunHitL || shotGunHitR) 
         {
             hitPoints = hitPoints - 5;
         }
     }

  
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 jfn73150 · Aug 22, 2018 at 04:44 PM

ANSWER
If anyone is having the same experience there is a much simpler solution.
Make a script for Particle Damage. Set that script on each actual particle system on your character.
In that script simply add -

         [SerializeField] int particleDamage = 1; //MUST BE SERIALIZEDFIELD
     
         public int GetDamage()
         {
             return particleDamage;
         }  

Then in your enemy damage script write -

 void OnParticleCollision(GameObject other)
     {        
         int damage = other.GetComponent<ParticleSystemDamage>().GetDamage(); //GetDamage()grabs damage level from each separate particle system component with the particle system damage script added to it.
         
         ProcessHit(damage);
 
         if(hitPoints <= 1)
         {
             KillEnemey();
         }
     }   
 
     void ProcessHit(int damage)
     {
         hitPoints = hitPoints - damage; //processes damage from GetDamage() above
         print("current hitpoints are " + hitPoints);
     }









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

88 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

Related Questions

How to make particle do damage 0 Answers

How to Make Particle Effects Function as a Trigger That Deals Damage 1 Answer

Cant assign global variable to method parameter variable 1 Answer

How to apply explosion/magic/grenade damage to detect objects (enemies) within a given radius, and apply AOE damage to each enemy based on its distance? 2 Answers

Head on collision vs skinning the wall. 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