• 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
4
Question by conflictbliz · Oct 23, 2011 at 12:16 AM · enemyshootblood

How to make my enemy bleed

i want it so when i shoot an enemy it will create a particle that is played once everytime it is shot so it looks like blood but i cannot seem to find any tutorials on how to do this? i know how to create a particle that is played once but i don't know how to script it

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 syclamoth · Oct 24, 2011 at 10:53 PM 4
Share

I love the name of this question.

2 Replies

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

Answer by aldonaletto · Oct 23, 2011 at 01:37 AM

Create the blood particles to splash blood upwards, set OneShot and Auto Destruct, and drag it to the Project panel to make it a prefab. If you are shooting the enemy with Raycast, instantiate the particles in the shooting script this way:

var bloodPrefab: GameObject; // drag the blood prefab here

... if (Physics.Raycast(ray, hit)){ // when you shoot... if (hit.transform.tag == "Enemy"){ // and hit an enemy... // find the necessary rotation... var rot = Quaternion.FromToRotation(Vector3.up, hit.normal); Instantiate(bloodPrefab, hit.point, rot); // and make the enemy bleed } } But if you are hitting the enemy with instantiated projectiles, add this code to the projectile script:

var bloodPrefab: GameObject; // drag the blood prefab here

function OnCollisionEnter(col: Collision){ if (col.transform.tag == "Enemy"){ var contact = col.contacts[0]; // get the first contact point info // find the necessary rotation... var rot = Quaternion.FromToRotation(Vector3.up, contact.normal); Instantiate(bloodPrefab, contact.point, rot); // and make the enemy bleed } Destroy(gameObject); // destroy the projectile }

Comment
Add comment · Show 9 · 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 conflictbliz · Oct 24, 2011 at 09:04 PM 0
Share

so i would attach the projectile script to my bullet so when it hits the enemy it will play the particle?

avatar image aldonaletto · Oct 24, 2011 at 09:59 PM 1
Share

Yes. If you are using a projectile to hit the enemy, attach the script above to the projectile prefab. When the projectile hits the enemy, it instantiates the blood particle at the contact point and destroy itself. You must set Auto Destruct and One Shot to true in the blood particle prefab, or else the blood will continue splashing in the same world point even after the enemy has moved to another place.

avatar image conflictbliz · Oct 25, 2011 at 05:14 AM 0
Share

Thank you so much i got it to work but when your a certain distance away it wont play the particle but that is not a big problem and i can deal with that its a really good script thanks for your help!!! :)

avatar image CHPedersen · Oct 25, 2011 at 07:30 AM 2
Share

[$$anonymous$$eta] is this question displaying "0" in the front page Answers counter for you guys as well? Looks like a QATO bug to me. O_O

avatar image aldonaletto · Oct 25, 2011 at 10:47 AM 0
Share

@Christian H Pedersen, it's a QATO bug, for sure. I saw other questions displaying 0 answers as well, and even an answered question displaying -1 answers!

Show more comments
avatar image
1

Answer by syclamoth · Oct 25, 2011 at 10:57 AM

Yep, that's definitely how it works. Is it displaying the right number now?

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.

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

6 People are following this question.

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

Related Questions

Blood on weapon. 1 Answer

Moving Enemies? 1 Answer

How do I make the enemy stop walking and shoot the player? 1 Answer

Shoot. Just Shoot 5 Answers

lock on enemy and shoot 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