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 mealone · Jul 19, 2014 at 04:15 AM · collisioncoroutineswipecombo

help with fruit ninja like slice combo

Hello. I am trying to script a combo where multiple prefabs tossed in the air like fruit ninja are sliced in one swipe. I want that when the swipe gameobject collides with three or more prefabs this creates a combo and then a "combo" prefab is spawned at the position of the last hit prefab saying 3,4, or 5 hit combo based on the number of prefabs hit with one swipe. I have no clue as to how to do this, and everything i tried does not seem to work.

This is what i have tried: in pseudocode - when the collision occurs with the swipe gameobject and the prefab, save the locations of the collisions in a list, then check the number of collisions which occurred in 1 second, which is the timeframe for the combo, and then spawn the correct combo gameobject at the last collision point based on the number of hits within the timeframe.

I tried this code below but could not get it to work. PLEASE HELP??

 var myHitList : List.<Vector3> = new List.<Vector3>();
 var hits : Collider2D[];
 var combo : GameObject;
 var combo1 : GameObject;
 var combo2 : GameObject;
 var combo3 : GameObject;
 var combo4: GameObject;
 var hit : float;
 
 
 function OnCollisionEnter2D(coll: Collision2D) {
     if (coll.gameObject.tag == "slice" && myHitList.Count == 0){
         Invoke ("Do", 1);
         Turn();
         }
     if (coll.gameObject.tag == "slice"){
         myHitList.Add(coll.gameObject.transform.position);
         }
     if(hit == 3)
         {
             Instantiate(combo, myHitList[myHitList.Count-1], Quaternion.identity);
             Instantiate(combo1, myHitList[myHitList.Count-1], Quaternion.identity);
         }    
     else if(hit == 4)
         {
             Instantiate(combo, myHitList[myHitList.Count-1], Quaternion.identity);
             Instantiate(combo2, myHitList[myHitList.Count-1], Quaternion.identity);
         }    
     else if(hit == 5)
         {
             Instantiate(combo, myHitList[myHitList.Count-1], Quaternion.identity);
             Instantiate(combo3, myHitList[myHitList.Count-1], Quaternion.identity);
         }    
     else if(hit == 6)
         {
             Instantiate(combo, myHitList[myHitList.Count-1], Quaternion.identity);
             Instantiate(combo4, myHitList[myHitList.Count-1], Quaternion.identity);
         }                
 }
 
 function Update() { 
 
 }
 
 function Turn (){
 yield WaitForSeconds (1.2);
 myHitList.Clear();
 hit=0;
 CancelInvoke("Do");
 }
 
 function Do (){
 hit = myHitList.Count;
 }
 
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 Eluate · Jul 19, 2014 at 05:27 AM

WaitForSeconds() requires you to use the StartCoroutine method.

 function OnCollisionEnter2D(coll: Collision2D) {
     if (coll.gameObject.tag == "slice" && myHitList.Count == 0){
         Invoke ("Do", 1);
         StartCoroutine(Turn());
         }
     if (coll.gameObject.tag == "slice"){
         myHitList.Add(coll.gameObject.transform.position);
         }
     if(hit == 3)
         {
             Instantiate(combo, myHitList[myHitList.Count-1], Quaternion.identity);
             Instantiate(combo1, myHitList[myHitList.Count-1], Quaternion.identity);
         }   
     else if(hit == 4)
         {
             Instantiate(combo, myHitList[myHitList.Count-1], Quaternion.identity);
             Instantiate(combo2, myHitList[myHitList.Count-1], Quaternion.identity);
         }   
     else if(hit == 5)
         {
             Instantiate(combo, myHitList[myHitList.Count-1], Quaternion.identity);
             Instantiate(combo3, myHitList[myHitList.Count-1], Quaternion.identity);
         }   
     else if(hit == 6)
         {
             Instantiate(combo, myHitList[myHitList.Count-1], Quaternion.identity);
             Instantiate(combo4, myHitList[myHitList.Count-1], Quaternion.identity);
         }               
 }
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 mealone · Jul 20, 2014 at 02:50 PM 0
Share

Hi. Thanks for your response. I entered the startcoroutine into the code as you suggested, however I'm still getting some issues with this. When three prefabs are hit right now nothing happens. Do you think there is a better way to accomplish this other than the code I tried?

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

24 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 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

help with scripting combo points 1 Answer

conditional gameobject spawning from collision array help please? 1 Answer

collision combo 1 Answer

Weird collision error when using waypoint script... 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