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 Twayne · Oct 08, 2010 at 07:03 AM · rendererparticle

How do I enable or disable a ParticleRenderer attached to an object in script?

I want to disable the ParticleRenderer attached to GameObject(Ball1) in script.

ball1 = GameObject.Find("Ball1");
ball1.ParticleRenderer.enabled = false;

that second line gives an error. How do I do this. Thanks

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 · Oct 08, 2010 at 07:43 AM

Using GetComponent works:

ball1 = GameObject.Find("Ball1");
ball1.GetComponent(ParticleRenderer).enabled = false;

If you're using #pragma strict or on the iPhone, you'll need to cast it as a Renderer:

(ball1.GetComponent(ParticleRenderer) as Renderer).enabled = false;

Depending on your setup, you could instead disable the ParticleEmitter:

ball1.particleEmitter.enabled = false;
Comment
Add comment · Show 6 · 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 Twayne · Oct 08, 2010 at 01:39 PM 0
Share

This gives error 'enabled' is not a member of 'UnityEngine.Component'. The second option gives no error but the particles are still working. I am using the code from the Lightening Bolt Demo in the Procedural Folder. While in game mode, unchecking the Particle Emitter or the Lightening Bolt script doesnt stop the bolt, but unchecking the Particle Renderer does.

avatar image · Oct 08, 2010 at 02:25 PM 0
Share

Are you using Unity3? The GetComponent approach works fine for me - tested locally. Perhaps you can post your full code in your question?

avatar image · Oct 08, 2010 at 02:29 PM 0
Share

Actually, are you building for iPhone? If so, take a look at this: http://answers.unity3d.com/questions/3138/why-am-i-getting-x-is-not-a-member-of-y-on-unity-iphone-when-it-works-regula

avatar image Twayne · Oct 08, 2010 at 03:07 PM 0
Share

Unity3 for windows not pro. Those are my only 2 lines of code in my script that reference Ball1 outside maybe the Lightening bolt script. I thank you for testing locally I. Will check for a possible syntax error when I get home tonite.

avatar image Twayne · Oct 09, 2010 at 03:05 AM 0
Share

The iPhone clue helped. The script has '#pragma strict' in it so same rules apply. The line that worked is. (ball1.GetComponent(ParticleRenderer) as Renderer).enabled = false;

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

No one has followed this question yet.

Related Questions

Changing two different objects renderer colour 1 Answer

Mesh Particle Emitter & Animation 0 Answers

Particle Hearts for Valentines Day 1 Answer

Accessing material of particle renderer?? 1 Answer

Trying to use trail renderer to create a flame trail 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