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 Aperture Dev · Sep 23, 2010 at 09:45 AM · errorparticleemitterdeclaration

How to enable a ParticleEmitter in scripting

Help, I need to make a particle emitter emit at MouseClick. I have gotten everything ready except the actual thing. I need to make the ellipsoid particle emitter emit, I really need some help. I have a main gameobject called gunprototype, and another object in it called maingun. The maingun object has the models etc. I have created a gameobject in the main 'gunprototype' object called Gun, and in Gun there is a ellipsoid particle emitter and the script. the problem is, it is giving me code errors like "cannot convert from UnityEngine.GameObject to UnityEngine.ParticleEmitter". I tagged the emitter with the tag "Seagull".

function Update () { var goEmitter : GameObject; var emitter : GameObject; goEmitter = GameObject.FindGameObjectsWithTag("Seagull");

if (Input.GetMouseButtonDown (0)) 
{
    BroadcastMessage("Firing!");
    goEmitter.Emitter.emit = true;
}

}

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
3

Answer by · Sep 23, 2010 at 10:02 AM

The error is because you're declaring 'emitter' as a GameObject, and then referring to it as a particleEmitter. I've updated your script and it should work (assuming that the gun is the only object with the "Seagull" tag (be aware that you can create your own tags too).

A few notes:

  • Put your 'Find' function in Awake() or Start() so it's only looked up once, and then cached.
  • FindGameObjectsWithTag returns an array of GameObjects, and you were only accessing the first.
  • You don't need Emitter. "particleEmitter" refers to the particleEmitter component on the gameObject.
  • Do you need to BroadcastMessage("Firing!") ? This attempts to call Firing!() on all GameObjects...

Hope this helps.

function Awake() { var goEmitter : GameObject = GameObject.FindWithTag("Seagull"); }

function Update () { if (Input.GetMouseButtonDown (0)) { BroadcastMessage("Firing!"); goEmitter.particleEmitter.emit = true; } }

Comment
Add comment · Show 2 · 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 Aperture Dev · Sep 25, 2010 at 05:46 AM 0
Share

Thanks a lot, that really helped!

avatar image · Sep 26, 2010 at 01:51 AM 0
Share

No worries. Remember to vote up any answers that helped you, and if it solves your question, mark it correct by clicking on the tick beneath the up/down arrows. Cheers

avatar image
0

Answer by jonas-echterhoff · Sep 23, 2010 at 10:02 AM

Try goEmitter.particleEmitter.emit = true;

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 · Sep 23, 2010 at 10:02 AM 0
Share

Heh, beaten by 10 seconds. Serves me right for being wordy.

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

No one has followed this question yet.

Related Questions

Errors in Vector2 variables 1 Answer

Particle Emitter error, Missing reference exception. 1 Answer

why this does not work (Lists) 3 Answers

Casting error on multiple emitters 3 Answers

C# Vector3 error: Expression denotes a `type'... 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