• 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 Darth Stefan · Mar 30, 2013 at 06:52 PM · particlesandflame

Script code for 'and' isn't working

Hello,

I am trying to make something working, but for reasons I do not know, it is not working. I have made a script to activate a particle flame when you're inside the trigger zone of the flame. That works fine!

I want to activate an animation if all flames are on, but for some reason it does not work. My guess, it has to do with the &&. This is my script:

     #pragma strict
     
     var flame:Transform;
     
     var flame1 = false;
     var flame2 = false;
     var flame3 = false;
     var flame4 = false;
     
     static var allFlame = 0;
     
     //var flameStart = false;
     var onFlame = false;
     
     function Start () 
     {
         flame.active = false;
     }
     
     function Update () 
     {
         if(onFlame && Stefan_Player.gotTorch)
         {
             flame.active = true;
             
             if(flame.name == "Flame1")
             {
                 print("flame1 is on");
                 flame1 = true;
                 
             }
             
             if(flame.name == "Flame2")
             {
                 print("flame2 is on");
                 flame2 = true;
                 
             }
             
             if(flame.name == "Flame3")
             {
                 print("flame3 is on");
                 flame3 = true;
                 
             }
             
             if(flame.name == "Flame4")
             {
                 print("flame4 is on");
                 flame4 = true;
             }
         }
         
         if(flame1 && flame2 && flame3 && flame4)
         {
             print("freaking BURRN!!");
         }
     }
     
     function OnTriggerEnter( hit : Collider )
     {
         if(hit.gameObject.tag == "Player" )
         {
             onFlame = true;
         }
     
     }
     
     function OnTriggerExit( hit : Collider )
     {
         if(hit.gameObject.tag == "Player" )
         {
             onFlame = false;
         }
     
     }
Comment
Add comment · Show 3
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 fafase · Mar 30, 2013 at 06:54 PM 1
Share

But do you see thge flame being on?

avatar image Darth Stefan · Mar 30, 2013 at 06:57 PM 1
Share

Yes the flames will go on! Everything is working except the &&'s

avatar image Fattie · Mar 30, 2013 at 09:12 PM 0
Share

"I am trying to make something working, but for reasons I do not know, it is not working."

totally awesome. a million points, happy easter!

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Owen-Reynolds · Mar 30, 2013 at 08:55 PM

The script is on each flame? That means flame1 has flame1-4, flame2 has a different flame1-4 ... . When flame2 goes on, it sets it's personal flame2 to true. But it's personal 1,3,4 will always be false. When all 4 flames are on, each one sees 1 true and 3 falses in their personal flame1-4 vars. Trick is to have a "master" variable that tells you if a certain flame is on.

I'd lose flame1-4, and keep OnFlame, except never set it false. Seems it would be simpler to just lose Update and simply set stuff in OnTrigger. But, either way, you now have 4 total flame vars -- each script has an OnFlame.

To check all 4, check onFlame for each trigger: if(GameObject.Find("fire1").GetComponent("fireScript").onFlame && ...).

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How do I use emissionRate in scripting? 1 Answer

how to have bullets produce particles? 2 Answers

How to lower thee effect of Gravity on Particles?/Shorter Trail when moving. 0 Answers

How do i script a particle effect to start? 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