• 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
Question by Jmontoya · Dec 27, 2010 at 10:59 PM · levelend

how to end a level?

I trying to end a level but i cant find a script to use. What script should i use to end the level when the player gets to a certain point?

Comment

People who like this

0 Show 0
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

5 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by heks · Dec 28, 2010 at 11:40 AM

Assuming the player represents a physical in-world RigidBody and that it has the tag Player set, you can detect when it enters a trigger and then load your end level scene. Add the following code to a script attached to the trigger (Collider) object:

function OnTriggerEnter(other : Collider)
{
    if(other.gameObject.CompareTag("Player"))
    {
        Application.LoadLevel("EndLevel");
    }
}

More information here:

http://unity3d.com/support/documentation/Manual/Physics.html http://unity3d.com/support/documentation/ScriptReference/Collider.html http://unity3d.com/support/documentation/ScriptReference/Application.LoadLevel.html

Comment
SrBilyon
JanEricsson
Seb_Astian28
ROAMSpider

People who like this

4 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 Karlos 42 · Oct 17, 2012 at 03:18 PM 0
Share

When i added this to my GameObject and walked into it the player just walked through the object.

avatar image SamyTaz · Jul 29, 2017 at 02:33 PM 0
Share

How to Stop All Game Sound in All Scenes by simply pressing On/Off Button Hello I'm New in this field So please help me .. I just want to stop all music by pressing a simple button "Off" from main menu and Want to Start Again All Sound of the game By Pressing another button "On" also located on main menu ...

i designed 20 Levels,Scenes for my game and want to stop All sound of the game from main menu But i can only stop the Sound,Music that is on the main menu when i go to the next scenes,Level Sound is not Mute .

I know its possible by using Void Awake() Function But i'm New So Please Give me the right solution,Logic ...Thanks

avatar image

Answer by tone20 · Aug 17, 2013 at 07:41 AM

dont forget to check "on trigger" button on the trigger

Comment
JanEricsson

People who like this

1 Show 0 · 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

Answer by Jesus_Freak · Dec 28, 2010 at 01:24 AM

*if(transform.position = Bector)
{
 Application.LoadLevel("nextlevel");
}
var Bector : Vector3;

But make sure you put the exact name of the level and add it to the build settings.

Comment

People who like this

0 Show 6 · 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 Jesus_Freak · Dec 28, 2010 at 01:24 AM 0
Share

Also, set Bector to wherever u want that spot to be.

avatar image Jesse Anders · Dec 28, 2010 at 02:03 AM 0
Share

You probably want '=', not '=='. Also, due to floating-point imprecision, performing exact comparisons between vectors as you're doing here is almost always a bad idea. (Better to use a distance check in this case, or perhaps a trigger.)

avatar image Jesus_Freak · Dec 28, 2010 at 02:44 AM 0
Share

You could use a trigger but could u explain how distance is better than comparing (==) to a point?

avatar image Mads Bgeskov · Dec 28, 2010 at 12:32 PM 0
Share

Because it is not very often that your transform.position will be complety equal to another point. Even if two objects may appear to be in the same place the floating point difference between the vectors could be .0001 which would make the check fail. Using if ( Vector3.Distance ( vec1, vec2 ) < threshold ) would therefore in most situations make more sense.

avatar image Jesse Anders · Dec 28, 2010 at 07:40 PM 0
Share

What Mads said. (Also, even with a threshold distance, having to move your character to a single, specific point would likely be prohibitively difficult, so you'd probably want to use a distance threshold that was relatively large relative to the movement speed of the character. Of course at that point you're basically replicating the behavior of a spherical trigger, so if the player character has a collider associated with it, you might as well just use the trigger.)

Show more comments
avatar image

Answer by joeybubble1 · Dec 28, 2010 at 11:28 AM

var levelToLoad: int;

function Start(){ levelToLoad = Application.loadedLevel+1; }

function OnTriggerEnter(collider : Collider) {

if(collider.gameObject.tag == "Player"){ Debug.Log("Player collided");
Application.LoadLevel(levelToLoad); } }

Comment

People who like this

0 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 Jesus_Freak · Dec 28, 2010 at 02:23 PM 0
Share

That's not very accurate, what if we just came from a main menu to some cheat menu and skipped some levels, then wouldnt it load the next level in line after cheat? Or what if their levels are messy in the build settings? Then it will go from level 1 to level 3 or something.

avatar image pwnisher · Oct 31, 2012 at 04:07 PM 0
Share

This script works nice !!! thanks you dude :)

avatar image

Answer by faramicool · Mar 04, 2013 at 04:07 PM

the best one is

var scene: string;

 funvtion OnTriggerEntr{
 
 application.LoadLevel(scene);
 
 }
Comment

People who like this

0 Show 0 · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Ending Level Help 1 Answer

Resetting the level without changing variables 0 Answers

Can't restart a level 2 Answers

Prefabs getting deleted in all scenes! 0 Answers

problem lightmap 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