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
1
Question by Oriek27 · Aug 18, 2010 at 04:25 AM · javascriptfpslevelloadlevel

Level advancment Scirpt

hey guys, I'm making a fps, and am making a script that automatically goes to the next level when all enemies are dead. it goes like this:

var target : Transform;

function Update ()

{

if(target == null && GameObject.FindWithTag("Robot") == null);

Application.LoadLevel(1);

}

the problem is than when i attach the script to a game Object (Ive tried different objects) and play, it shows level 0 for 2 seconds, then loads level 1!

Ive tried modifying the tag and using Application.LoadLevel(Application.loadedLevel + 1); but it still doesnt work!

please help

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

Answer by · Aug 18, 2010 at 04:53 AM

You had a semicolon after the if, so it wasn't doing anything after the ifcheck. The Application.LoadLevel would always occur. Try this:

var target : Transform;

function Update ()

{ if(target == null && GameObject.FindWithTag("Robot") == null) { Application.LoadLevel(1); } }

Another thing to be wary of is that the Find/FindWithTag functions are quite intensive, and should generally not be used in Update() - as it is, you're searching every GameObject for one with the "Robot" tag every frame. You'd be much better off putting that in a seperate function and calling it when an enemy dies (to check if there are any left). For example:

function CheckForEnemies()
{
   if (GameObject.FindWithTag("Robot") == null)
   {
      Application.LoadLevel(1);
   }
}

You'd then need to hook this function up to where you apply damage. For example:

function ApplyDamage(damage : int) { this.health -= damage; // apply the damage that has been passed through

if ( this.health <= 0 ) // if the enemy is now dead (<=0 health remaining) { CheckForEnemies(); } }

This is just an example - there may be a better way to hook it up, depending on the design/structure of your game. Other things to consider would be changing the LoadLevel from a static value to use a variable. You could have a "gameManager" object that stores a 'static variable' for the currentLevel, and then you could Application.LoadLevel(currentLevel+1), or put it in a function that checked if it was the last level, etc. Anyway, hopefully this will get you started.

Comment
Add comment · Show 2 · 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 Oriek27 · Aug 18, 2010 at 04:59 AM 0
Share

ok, that sounds much more organized, but how would i do that? oh, and thanks for the tip about the extra semicolon. also how would i make it fade? i have a "LevelLoadFade" script, but where would i attach that?

avatar image · Aug 18, 2010 at 06:32 AM 1
Share

I've updated the answer to include some examples. Without knowing how you've structured your data, I can only guess at how you'd best approach implementing a solution! Hope this helps.

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

No one has followed this question yet.

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Basic scripting help (FPS Tutorial) 1 Answer

Next lvl code help 1 Answer

Does Anyone Have a Halo-Like Scripts? 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