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 Leedzie · Oct 01, 2012 at 01:56 AM · instantiateparticlesoncollisionenterif statementoncollisionexit

Instantiate particles with double if statement

Hello everyone, first time posting, as normally I can find the answers to my questions by searching around here. However, I have a project due Tuesday, and I can't seem to find any help for this issue I'm having.

I'm making a game that involves mixing food into a pot, and depending on what ingredients you put in together, different particle systems will be emitted. As I've been building this up I've tested along the way, and I was able to get the particles to instantiate when I put in only one ingredient using OnCollisionEnter. However, I hit the problem of only being able to enter one argument into that function, so I switched to booleans and if statements instead. I have it set up so that the booleans are switched to true if the pot detects a collision with the corresponding object.

From there, I figured it'd be a very simple matter of checking if any given two booleans were true at the same time with a set of if statements, and then instantiating the desired particle system. However, I can't seem to find a way to get this last step functioning. I've been Googling around and searching the forums for any particle instantiation tips I can find, and I've tried them all, but nothing seems to be working so far. I'm desperate for help, because this game is due in 2 days, and if I can't get this to function, I won't have a game at all!

EDIT: I should mention that I intended to put all of the particle systems into the array declared at the top, and instantiate them by calling on their array number down at the bottom.

Here is the code I've been testing with:

 var prefab:GameObject[];
 
 var apple:boolean = false;
 var turkey:boolean = false;
 
 function Update () 
 {
     Shenanigans();
 }
 
 
 function OnCollisionEnter(ingredient:Collision)
 {
     if(ingredient.gameObject.tag == "Apple")
     {
         apple = true;
     }
     if(ingredient.gameObject.tag == "Turkey")
     {
         turkey = true;
         
     }
 }
 
 function OnCollisionExit(ingredient:Collision)
 {
     if(ingredient.gameObject.tag == "Apple")
     {
         apple = false;
         
     }
     if(ingredient.gameObject.tag == "Turkey")
     {
         turkey = false;
         
     }
 }
 
 
 function Shenanigans()
 {
     if(apple && turkey)
     {
         Instantiate(prefab[0],transform.position,transform.rotation);
 yield WaitForSeconds(5);
         Destroy(prefab[0]);
         return;
     }
 }

Any help would be deeply appreciated!!

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

Answer by DaveA · Oct 01, 2012 at 02:29 AM

You may need to include more code but here's my $.02

  1. You would need to check apple and turkey in an Update function, not just on Awake, but you could also do this OnCollisionEnter only.

  2. You could have the particle systems already there, just not active (not emitting) unless/until the collision happens.

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 Leedzie · Oct 01, 2012 at 02:36 PM 0
Share

(I apologize in advance if this posts twice. I wasn't sure if the first one went through.)

Thank you, that was very helpful! When I moved the call to check the if statements to Update, the particles instantiated.

However, this has given me a new problem: I can't seem to get them to only instantiate once. The particles keep instantiating once every update; what I need is to instantiate once, run through the particles, and then remove it. I tried using a yield and Destroy, but I think I may be using it incorrectly, because it appears to have no effect. I've updated the OP coding to reflect the new changes.

Thank you for any additional help!

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

12 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

Related Questions

How Would I instantiate a particle system onto my obstacle on collision after it being destroyed? 0 Answers

Audio and Particles on Trigger 0 Answers

Spawning individual particles at scene coordinates. 1 Answer

How to Instantiate gameObject where a particle dies 2 Answers

Explosion on contact? 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