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 Aerovistae · Nov 30, 2012 at 12:56 AM · gameobjectparticlesfindgameobjectswithtag

How do I both "find" this and stop it from emitting?

With the following code, I get one of two problems:

  1. If I declare `inner` and `outer` as ParticleEmitters, it tells me it can't convert a GameObject to a ParticleEmitter when I use the `FindGameObjectWithTag()` method.

  2. If I declare them as GameObjects, then that works, but then it tells me there's no `emit` method on GameObject.

Here's the code, currently in the first form. How can I accomplish this?

 var inner: ParticleEmitter;
 var outer: ParticleEmitter;
 
 function Start () {
 inner = GameObject.FindGameObjectWithTag("flame_inner");
 outer = GameObject.FindGameObjectWithTag("flame_outer");
 inner.emit = false;
 outer.emit = false; 
 
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Nov 30, 2012 at 01:14 AM

The GameObject provides access to some popular components, including the ParticleEmitter - you can use it when finding the GameObject:

 function Start(){
   // FindWithTag does the same as FindGameObjectWithTag:
   inner = GameObject.FindWithTag("flame_inner").particleEmitter;
   outer = GameObject.FindWithTag("flame_inner").particleEmitter;
   inner.emit = false;
   outer.emit = false;
 }
 
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
avatar image
0

Answer by DecipherOne · Nov 30, 2012 at 01:16 AM

The ParticleEmitter has to be instanced in order to use it. In other words, with what you have you aren't actually assigning an object. If you have the particles emitters in your scene already, you can simply declare a public game object, assign the object in your scene using the inspector in the editor. Then you will want to access the particle emitter component. Also, if the functionality is something that you are going to use in multiple spots, I'd recommend just creating a generic script that you can reuse. In C# it may look something like this :

 using UnityEngine;
 using System.Collections;
 
 public class SetParticles : MonoBehaviour {
     
     public GameObject myEmitter;
     ParticleEmitter  myRef;
     public bool emit;
 
     void Start () 
     {
         
         myRef = myEmitter.GetComponent ("ParticleEmitter") as ParticleEmitter;
         myRef.emit = emit;
 
     }
 
 
 
     
     // Update is called once per frame
     void Update () {
     
     }
 }


You then would simply assign the GameObject with a ParticleEmitter through the inspector. If you are doing things dynamically, it gets a little bit more involved, but still the same general idea.

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

13 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

Related Questions

store GameObject.FindGameObjectsWithTag in an array 2 Answers

One particle pulse when gameobject is destroyed. 2 Answers

Need help finding the closet player to an enemy 2 Answers

Getcomponent error? 1 Answer

Targeted Electric Charge Particle Effect 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