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 amuro21aya · Feb 16, 2012 at 05:12 AM · objectdestroylevel

Can't proceed next level when the object destroy not complete.

I don't know how to script if the 4 objects in the scene did not destroy then he did not proceed to the next level of the game. -i have 4 object in my game play the player then to destroy all the 4 objects to go in the next level. how is it? please help me.

Comment
Add comment · Show 1
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 by0log1c · Feb 16, 2012 at 05:30 AM 0
Share

sure thing, mate: http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-%28long%29?highlight=newbie+javascript

2 Replies

· Add your reply
  • Sort: 
avatar image
-1

Answer by mesho · Feb 16, 2012 at 05:37 AM

simply add Application.loadedLevel ("levelName");

Before the Destroy action not After it

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
avatar image
0

Answer by BiG · Feb 16, 2012 at 07:30 AM

Add a function OnDestroy( ) to each one of your 4 objects. In this function, you'll simply turn a boolean variable to TRUE. When all the four variables are TRUE, you can access next level. What I mean is something like this:

(NOTE: the following code is untested, and its purpose is just to give you a general idea on this)


This is a global variable, and it'll contains all the flags for checking the destructions:

var flags : boolean[] = new boolean[4];


This script is attached to each one of the 4 objects (with different "object_index"!!!), and this will be activated if the object is destroied:

var object_index = 1; //object_index's value is 1 for the 1° object, 2 for the 2° one,...,4 for the 4° one
function OnDestroy(){
   flags[object_index] = 1;
}


This function has to be called from the Update() of the object in which you check for the level changing:

function Update(){ //... Check_next_level; //... }

function Check_next_level(){ going_to_next_level = 1; for (var i=1; i++; i<5){ if (flags[i] == 0){ going_to_next_level = 0; break; } } if (going_to_next_level){ level_index++; //You have to declare this outside, and use it to mantain the reference to the actual level Application.LoadLevel(level_index); } }

Comment
Add comment · Show 5 · 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 amuro21aya · Feb 18, 2012 at 04:30 AM 0
Share

what do you mean by FLAGS and object_index? Thanks

avatar image amuro21aya · Feb 18, 2012 at 06:37 AM 0
Share

this all script is in one file?

avatar image BiG · Feb 18, 2012 at 09:45 PM 0
Share

flags is an array and flags[object_index] is equal to 1 if that object has been destroied (so, flags[2]=1 means that the 2° object has been destroied). And no, they are not "in one file": the first script has to be attached to each one of the 4 objects; the second one, it depends by the point in which you check for the next level.

avatar image amuro21aya · Feb 19, 2012 at 05:28 AM 0
Share

var puzzle : boolean[] = new boolean[4]; var 4 = 1; function OnDestroy(){ flags[4] = 1;

  • i am right??

avatar image amuro21aya · Feb 19, 2012 at 05:37 AM 0
Share

i try to edit the script you give. I am right?

function Update(){ //... Check_next_level; //... }

function Check_next_level(){ going_to_next_level = 1; for (var i=1; i++; i<5){ if (flags[i] == 0){ going_to_next_level = 0; break; } } if (going_to_next_level){ level_index++; -->should i change it? Application.LoadLevel(level_index); } }

->this is right

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Change level after destroying all enemies? 1 Answer

Destroying specific clone object while not destroying others on screen 5 Answers

Level spawning statement help 0 Answers

Object won't instantiate at parents position(solved) 2 Answers

Destroy Object during animation 2 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