Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by GFRibeiro · Oct 23, 2015 at 02:30 PM · collision detectionfalsetrue

Solving the JavaScript paradox of: if(x equal true){x becomes false;} if(x equals false){x becomes true;}. Beginner question.

Hi, I've just started using Unity and this is my first question. I searched for similar question using keywords like "true", "false", and "collision", but none of the treads answered my question, so please allow me to ask here.

I am trying to write a JavaScript code, attached to a Sphere, that besides other processes, recognizes when the sphere hits a Cube. When it does, the cubes tagged "Player" emits particles. If it is already emitting, it pauses, and if it is paused, it emits again. The script is as follows (I believe "function OnCollisionEnter(collision:Collision)" is the only part relevant, but I will post the whole script just to be sure):

 #pragma strict
 
 function FixedUpdate (){
     var x:float = Input.GetAxis("Horizontal");
     var y:float = Input.GetAxis("Vertical");
     rigidbody.AddForce(x, 0, y);
 }
 
 function Start(){
     var Cube:GameObject = gameObject.Find('Cube');
     var particle:ParticleSystem = Cube.gameObject.GetComponent('ParticleSystem');
     
     particle.Play();
 }
 
 function OnCollisionEnter (collision:Collision){
     if (collision.gameObject.tag == "Player"){
         var halo:Behaviour = collision.gameObject.GetComponent('Halo');
         halo.enabled = true;
         var particle:ParticleSystem = collision.gameObject.GetComponent('ParticleSystem');
         
         if(particle.isPaused == false){particle.Pause();}
         if(particle.isPaused == true){particle.Play();}
     }
 }
 
 function OnCollisionExit (collision:Collision){
     if (collision.gameObject.tag == "Player"){
         var halo:Behaviour = collision.gameObject.GetComponent('Halo');
         halo.enabled = false;
     }
 }

I assume since Unity reads the script from top to bottom, after pausing the particle emission, isPaused becomes true, triggering particle.Play(); which means the particle emission won't pause at all.

How can I make unity recognize whether or not the particle emission is paused at collision time, and act accordingly? Or any other solution is fine as well.

Thank you for your time.

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
0
Best Answer

Answer by springwater · Oct 23, 2015 at 03:50 PM

@GFRibeiro, The logic might be like this, assuming the player gets hit by a fireball for example and emits fire particles. "else" is the key word to straighten things out in these cases in my experience.

     OnCollisionEnter (collision:Collision){
     if (particle.isPaused == true)
      particle.Play();
     else 
     particle.Pause();
     }

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 GFRibeiro · Oct 23, 2015 at 06:21 PM 0
Share

Thank you very much!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

My method is called more than once. 1 Answer

How to save Component 1 Answer

Assets/health.cs(11,23): error CS1519: Unexpected symbol `=' in class, struct, or interface member declaration 1 Answer

Animation Problem 0 Answers

script enable=false 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