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 VIDesignStudios · Nov 07, 2015 at 07:27 AM · ontriggerenterparticle systemontriggerstayparticle emitter

Particle System emits on Trigger Stay, in Unity 5

Hi, I'm trying to have a particle system emit only while a tagged object is touching/overlapping it. I need code for a trigger event that works with Unity 5 and specifies the tag of the object that touches it ("rightSide").

So far I know I need onTriggerStay (most code examples are one hit onTriggerEnter events), and one of the two objects need to have a Rigidbody component. http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerStay.html

The Unity docs say to use this true/false format instead of .Play and .Stop: ParticleEmitter.enabled public bool enabled; http://docs.unity3d.com/ScriptReference/ParticleEmitter-enabled.html

I found a great video explaining trigger vs collider and that we should never use Collide unless there's two physics objects coming together where it matters what angle and exact polygon(s), like in emitting dust at the right angle after a ball hits the ground. It also mentions concave shapes won't work as colliders. https://www.youtube.com/watch?v=IG2Bj80IT2Q

Old Code just for reference. Uses key press to toggle and works for other purposes.

using UnityEngine; using System.Collections;

public class light : MonoBehaviour { protected bool letPlay = true;

 public void Update()
 {
     if (Input.GetKeyDown(KeyCode.E))
     {
         letPlay = !letPlay;
     }

     if (letPlay)
     {
         if (!gameObject.GetComponent<ParticleSystem>().isPlaying)
         {
             gameObject.GetComponent<ParticleSystem>().Play();
         }
     }
     else
     {
         if (gameObject.GetComponent<ParticleSystem>().isPlaying)
         {
             gameObject.GetComponent<ParticleSystem>().Stop();
         }
     }
 }

}

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
2
Best Answer

Answer by NightLucididty · Nov 07, 2015 at 10:41 AM

I do not think that you can specify on what side of the collider the collision is but you can create an empty game object with a collider and attach it as a child to your main object, and have the collider be on the right side. And than you could do the same for another side if you have a similar function for another side like left, up, down... As for the code, now something similar to what was on the Scripting API,

 void OnTriggerStay(Collider collider) {
         if (collider.tag == "TagGivenToChildGameObject")
             gameObject.GetComponent<ParticleSystem>().Play();
     }

You say that you need to enable it or disable it as a bool, but that is only another method to do it, Your old code should work, Feel free to reply if you have anything else, Nightlucidity

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 VIDesignStudios · Aug 02, 2016 at 06:09 AM 0
Share

Thanks! Adding a child Collider object on the side worked best like you said. I'd run into another issue and wasn't sure if it was my code's fault until I resolved it. Works great now, sorry for the slow response!

void OnTriggerEnter(Collider other) { if (other.tag == "wand") { stars.Play (); Debug.Log ("object Wand has started the particle emitter Stars"); } else { Debug.Log ("something other than Wand has entered triggerspace"); return; }

 }
 void OnTriggerExit(Collider other)
 {
     if (other.tag == "wand")
     {
         stars.Stop();
         Debug.Log("object Wand has stopped the particle emitter Stars");
     } else {
         Debug.Log ("something other than Wand has exited triggerspace");
         return;
     }
 }

}

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

Have "OnTriggerStay" detection but only call it once? 1 Answer

Plugin to integrate .pex file compatible with unity 3D 0 Answers

BigExplosion won't stop bursting 0 Answers

Making a texture influence particle lifetime 0 Answers

Simple one-way teleport? 2 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