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 crusherxman · Nov 25, 2013 at 12:18 AM · particleplayenable

Play particle effect when Space Bar is pressed

I'm currently working a "Cannon Defense" game and I've been searching across Unity Answers and Google for the exactly same subject but there's nothing I couldn't find at all. I actually purchased an explosion+gun particle asset that I needed for my project. Could anyone help me with this? All I'm asking is a script that plays a particle effect whenever I press the Space Bar.

Here's my script:

Download HTSpriteSheet Script

Thanks

htspritesheet.zip (2.8 kB)
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 clunk47 · Nov 25, 2013 at 12:25 AM

EDIT: (User turns out not to be using a particle system, but HTSpriteSheet.cs).

Just add a new script to the GameObject that HTSpriteSheet is attached to, and enable / disable the script like so:

 using UnityEngine;
 using System.Collections;
 
 public class Example : MonoBehaviour 
 {
     bool animate = false;
     HTSpriteSheet htss;
 
     void Start()
     {
        htss = GetComponent<HTSpriteSheet>();
     }
 
     void Update () 
     {
        htss.enabled = animate;
 
        if(Input.GetKeyDown (KeyCode.Space))
          animate = !animate;
     }
 }
 

Be sure your script's name is the same as the class name.

Comment
Add comment · Show 10 · 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 crusherxman · Nov 25, 2013 at 12:26 AM 0
Share

Just before I try it out, what's a "Shuriken system"? (Never heared of this before)

avatar image clunk47 · Nov 25, 2013 at 12:34 AM 2
Share

Try the script and you'll know if you're using it lol. http://docs.unity3d.com/Documentation/Components/class-ParticleSystem.html

avatar image clunk47 · Nov 25, 2013 at 01:03 AM 1
Share

lol ok so if you're using Legacy particles, use the code in my answer. If you're using Shuriken, use the same code, except change

 particleEmitter.emit = emit;

TO

 particleSystem.enableEmission = emit;

 
avatar image clunk47 · Nov 25, 2013 at 01:09 AM 1
Share

Since you're accessing the component directly, this means you attach the script to the object with the particleSystem component attached, which is the particle system itself. If you're using Shuriken, you'll just have Particle System component. If you're using Legacy, you'll see Ellipsoid Particle Emitter, Particle Animator, and Particle Renderer components attached to the object.

avatar image clunk47 · Nov 26, 2013 at 01:06 AM 2
Share

Look in the script where it reads

 public class Example : $$anonymous$$onoBehaviour

The script's name needs to match the class's name. Either name your script 'Example', or change the name of the class inside the script to match what you have your script named as.

Show more comments

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

17 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Enable/Disable shader on script 2 Answers

Particles do not appear on play but do on emit 0 Answers

How to create particle system on a collision? 1 Answer

Particle follow object 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