Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 $$anonymous$$ · Jun 08, 2013 at 01:07 AM · prefabparticlesshootingparticle

Firing a particle effect prefab from your character

Hello everyone,

Have had some trouble coming up with the best ways to fire a particle effect prefab from the character in a first person view. Have googled around and most answers come in javascript where I am currently using C# (wanting a change from UnrealScript since switching to Unity).

Have documentation open and have been reading, thought I'd ask the awesome community here for some simple advice on what would the best way to do this be? Seeing a lot of different answers all around.

Cheers.

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 iwaldrop · Jun 08, 2013 at 01:40 AM

The simplest way would be to have a reference transform at the point where you want to spawn the particle effect. Ideally you have a spawn pool to work from that will cache n number of particle prefabs, but to get started you can simply have a GameObject member variable to hold a reference to the prefab that you'll be spawning. Once the setup is complete just instantiate the prefab at the position. You'll probably want a projectile type script on the prefab you're spawning that will drive your projectile, but you could also drive it from the 'gun'.

 void OnFireGun()
 {
     GameObject projectile = GameObject.Instantiate(projectilePrefab, spawnRef.position, spawnRef.rotation) as GameObject;
 }
 
 
 // on the projectile
 
 [RequireComponent(typeof(Rigidbody))]
 public class Projectile : Monobehaviour
 ...
 void OnAwake()
 {
     Rigidbody r = rigidbody;
     if (r != null)
         r.AddForce(transform.forward * speed, ForceMode.Impulse)
 }
 
 // OR, for rocket type projectiles that continually accelerate
 // cache a reference to the rigidbody in OnAwake
 Rigidbody r;
 void FixedUpdate()
 {
         r.AddForce(transform.forward * speed, ForceMode.Acceleration)
 }

Ask 10 people get 10 different answers as to the 'best' way. Experiment with what you find and you will soon discover a 'best' way of your own. It all depends on what your use case is. Welcome to Unity!

Comment
Add comment · Show 1 · 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 $$anonymous$$ · Jun 08, 2013 at 05:35 AM 0
Share

Thank you, that definitely clears my head up a bit and can now comfortably continue and add everything I wanted to.

Cheers!

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

14 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

Related Questions

Can a Particle System Use Custom Objects/Prefabs as Particles? 1 Answer

Is it possible to use Prefabs in the Particle emitter instead of meshes or billboards 1 Answer

Play after collision a Particle-prefab and spawn a new Coin-Prefab 1 Answer

how to rotate particles in a particle system 1 Answer

Move Particles 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