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
1
Question by bchevriaut · Nov 16, 2014 at 04:26 AM · c#particlesystem

Activate a particle system on click c# script

Hi,

I am actually new to Unity and i have a question.

I actually have a first person controller and a weapon attached to it. I put a particle system on my scene (https://www.assetstore.unity3d.com/en/#!/content/1) and i would like to activate it when I press 'fire'

This is my script (on my first person controller)

 public Transform origin;
     public Object bullet;
     public ParticleSystem detonator;
     private float lastShoot = 0;
     
     // Update is called once per frame
     void Update ()
     {
         // pas de spamm de clic
         if (Input.GetButton ("Fire1") && Time.realtimeSinceStartup - lastShoot > (1.0/4.0)) {
             lastShoot = Time.realtimeSinceStartup;
 
             // animation
             detonator.enableEmission = true;
             detonator.Play();
         }
     }

Nothing appens, my particle system is not playing.

If you have any ideas.. Have a good weekend

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 incorrect · Nov 17, 2014 at 05:35 PM 0
Share

I bet it's better to use 1.0f/4.0f if you did mentioned floats, not doubles. )

1 Reply

· Add your reply
  • Sort: 
avatar image
-1
Wiki

Answer by aliaavatar · Dec 22, 2014 at 10:37 AM

Put you ParticleSytem Prefab in you Resource folder. Then Load it into the Scene. Then use Instantiate(). I'm using the Elementals Particle System myself: https://www.assetstore.unity3d.com/en/#!/content/11158

Your case is simpler, since you only need to Instantiate the Particle System on the Weapon's tip and parent it to the weapon: use particle.transform.parent = weapon.transform;

Here's my code. It gets a bit more complicates here, as I make the splash as the cannons hit the water, but it's useful if you want to add explosions to wherever the bullets hit.

public Object Splasher;

void Start()

{

Splasher = Resources.Load("Splash"); }

public void Make_a_Splash(GameObject canonball) {

GameObject particle = GameObject.Instantiate(Splasher, canonball.transform.position, Quaternion.identity) as GameObject;

StartCoroutine(Cleanup_a_Blast(particle));

 }

void Update() {

     if(Input.GetKeyUp(KeyCode.Alpha1))
   ...Make_a_Splash(GameObject canonball)  

//adds the splash to where the cannons hit. //Cannons need to have a collider as a trigger attached.

}

 public IEnumerator Cleanup_a_Blast(GameObject blast)
 {
     yield return new WaitForSeconds(2);
     GameObject.Destroy(blast);
 }
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Simple C# script to move a gameObject toward the direction of the player at the instance of it's spawning. 1 Answer

Distribute terrain in zones 3 Answers

c# - void method from external class. 2 Answers

Multiple Cars not working 1 Answer

Why can't I edit C# script although I have monodevelop installed? PLEASE HELP 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