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 NickEberhart · Jul 06, 2016 at 04:59 PM · particlesystemplatformercodepage

Triggering particles with code

I am creating a simple platformer. When the player collides with the ground he respawns at the begening of the level. I also want a short little particle system to trigger and shoot out from him. I decided to write that part in the same script as the respawning. I can't get it to work though. I hope someone can help. (The respawning works fine, just need help with particle system) (C#)

 using UnityEngine;
 using System.Collections;
 
 public class KillZone : MonoBehaviour {
 
     GameObject player;
     Vector3 respawn;
     var particle ParticleSystem;
 
     void Start () {
 
         player = GameObject.Find ("Player");
         respawn = GameObject.Find ("Respawn").transform.position;
     }
 
     void OnTriggerEnter2D (Collider2D col) {
 
         Debug.Log ("Killzone Collision Detected");
         particle.Play ();
         player.transform.position = respawn;
     }
 }
Comment
Add comment · Show 7
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 Cherno · Jul 06, 2016 at 10:09 PM 0
Share

Try ParticleSystem.Emit() ins$$anonymous$$d.

avatar image NickEberhart Cherno · Jul 07, 2016 at 12:10 AM 0
Share

alt text

I get these errors when I make that change

errrors.png (9.4 kB)
avatar image Arkaid NickEberhart · Jul 07, 2016 at 01:45 AM 0
Share

This looks weird

 var particle ParticleSystem;

Don't you mean?

 ParticleSystem particle;

Also, you don't seem to be assigning the particle variable anywhere.

Show more comments
avatar image NickEberhart Cherno · Jul 07, 2016 at 01:00 PM 0
Share

That works great, thanks for the help. Sorry for my lack of knowledge!

avatar image Cherno NickEberhart · Jul 07, 2016 at 01:10 PM 1
Share

I converted my comment with the script to an answer. Please mark it as accepted to help others having a similar problem.

1 Reply

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

Answer by Cherno · Jul 07, 2016 at 12:55 PM

 using UnityEngine;
  using System.Collections;
  
  public class KillZone : MonoBehaviour {
  
      GameObject player;
      Vector3 respawn;
      public ParticleSystem particle ;
  
      void Start () {
  
          player = GameObject.Find ("Player");
          respawn = GameObject.Find ("Respawn").transform.position;
      }
  
      void OnTriggerEnter2D (Collider2D col) {
  
          Debug.Log ("Killzone Collision Detected");
          particle.Emit(30);
          player.transform.position = respawn;
      }
  }

Of course, you somehow have to assign a value to the particle variable, either by script or by dragging your ParticleSystem into the field next to the variable in the inspector.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to destroy only one GameObject??? 0 Answers

Particle System with multple collision behaviors for different layers? 0 Answers

2D 360 degress platformer example needed 0 Answers

How do I get my character to dash up? 0 Answers

Particle System won't play on awake 0 Answers


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