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 artsdcs · Jun 04, 2012 at 09:59 PM · erroriffirestatement

some scripting help

hey everybody i'm still realy new to unity and i'm trying to write a script but i'm affraid i need some help.

i had a cube where i added a particle renderer a particle emitter and a particle animator. i have a script that enables me to turn those off. but i also have a box collider on the cube that i want to turn off when the particles are off.

that's were i came up with this:

if( ParticleRenderer == false || BoxCollider == false )

only thing is that it doesn't work.

it gives me an error that says:

Assets/firesteptrough.js(2,1): BCE0043: Unexpected token: .

while there is nothing there.

so if you're willing to help me a bit with this i thank you.

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 Berenger · Jun 04, 2012 at 10:01 PM

Could you rephrase your second line, it's not very clear ?

Anyway, ParticleRenderer and BoxCollider are types, not boolean. You probably mean

if( !GetComponent( "ParticleRenderer" ).enabled || !collider.enabled ) ...

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 artsdcs · Jun 04, 2012 at 10:08 PM 0
Share

maybe a bit clearer like this?

avatar image Berenger · Jun 04, 2012 at 10:15 PM 0
Share

Yes, thank you. That's what I thought, and my code is relevant. So is hijinxbassist's answer.

avatar image
0

Answer by hijinxbassist · Jun 04, 2012 at 10:10 PM

Is this line 2? One thing to point out right off the bat is the use of BoxCollider and ParticleRenderer. They should reference a specific instance of the class and not the class itself. Instead it would look more like.

 public var myPlayer:Transform;
 
 function Start()
 {
     if(myPlayer.collider.enabled==false)//Do something
 }

Here i am referencing the collider on the object player where collider will refer to whatever collider is there whether its a box, sphere, or other. If you have multiple colliders you would need to get the correct collider by using GetComponent(BoxCollider). As for the 'particle renderer', you may just want to do whatever when it is done emitting?

 if(!myParticleSystem.isPlaying)//Do Something

so in your context in would be

 if(!myParticleSystem.isPlaying)
 {
     objectInQuestion.collider.enabled=false;
 }
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 artsdcs · Jun 05, 2012 at 12:21 PM 0
Share

i think i dont really get it. do i put the last piece in the scipt and then thats it or do i need to write some other stuff on it?

avatar image hijinxbassist · Jun 06, 2012 at 08:10 AM 0
Share

Wow, i wrote a whole nice explanation and pressed the wrong button :( Heres a recap to my hard worked comment which none will ever see.

To answer your comment, yes it will work as long as all the holes are filled in correctly. The code below is reasonably commented, should help.

 //Script on your 'cube', this is just an example
 
 private var particleSystem:ParticleSystem;
 private var boxCollider:Collider;
 
 function Start()
 {
     boxCollider=transform.collider;//if this cube only has one collider
     //Otherwise say
     //boxCollider=transform.GetComponent(BoxCollider);
 
     //If you are using a particle system that is attached to the 'cube'
     //otherwise make a public var and drag the particle system in inspector
     particleSystem=transform.GetComponent(ParticleSystem);
 
     //Either of these lines can be used in context, w/o the declaration :)
     //If you are unsure of what i mean by 'w/o declaration' :
     //transform.collider.enabled=false; //turns off collider
     //transform.GetComponent(ParticleSystem); //refers to prtclSystem
 }
 
 function Update() //as a working example only, not efficient
 {
     if(!particleSystem.isPlaying)//particle system is not emitting
     {
         boxCollider.enabled=false;//turns off the collider
         //Same as: transform.collider.enabled=false;
         //if there is only one collider on the 'cube'
     }
 }

I hope that helps you understand how to access single components.

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

My backpack script doubt 0 Answers

unity script error 1 Answer

How to finish my else if statement? 2 Answers

Unity Script Editor Not Working 1 Answer

Need help with multiple if statements. 3 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