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 buckethead3495 · Jun 21, 2010 at 03:21 AM · switch scenes

Script for changing levels

I need a script for changing levels once I reach a simple object (in this case a cube), can somebody give me this script?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Ashkan_gc · Jun 21, 2010 at 06:42 AM

add a collider to that cube object that you want to change level when colliding with it. check the is trigger of the collider that you attached and write something like this in a script.

function OnTriggerEnter (other : Collider)
{
if (other.tag = "player")
{
   Application.LoadLevel ("levelname"); 
}

put the level name in the "" you can expose this as a string and set it inside the inspector or just create a manager.

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 CLstream · Feb 16, 2013 at 08:29 PM 0
Share

It didn't work for me, do I have to use C# or Javascript?

avatar image
4

Answer by karl_ · Jun 21, 2010 at 03:31 AM

Typically people won't just write scripts for you, but here is the documentation for what you're trying to do. Place this after an OnTriggerEnter or OnColliderEnter for your cube.

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

Also, here's the docs for Trigger enters and Collision enter:

http://unity3d.com/support/documentation/ScriptReference/Collider.OnTriggerEnter.html

http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html

Edit: Alternatively, Fishman92 has answered this question exactly here:

http://answers.unity3d.com/questions/8196/a-game-with-multiple-levels

as well as one I answered:

http://answers.unity3d.com/questions/9097/move-to-next-level-on-collide

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 HJJ · Oct 23, 2011 at 09:32 PM

Here's a script I got from unity-It works really well on almost and object that has a collider:


using UnityEngine;

using System.Collections;

//extend MonoBehaviour so that we can attach this script to an object

public class creditsload: MonoBehaviour

{

     //A public bool so that we can change in the editor whether or not the button will quit the application

     public bool isQuit = false;

 

     //For the next three functions, the collider is absolutely necessary

     //these functions will not fire off if there is no collider







     //Fires off when the mouse hovers over the collider

     //When the mouse is over the item, change the colour of it to 

     //red so that the player knows that it is interacting with it

     void OnMouseEnter()

     {

             renderer.material.color = Color.grey;

     }

 

     //Fires off when the mouse leaves the object

     //We want to change the colour of the object back to it's original when the mouse 

     //is no longer over it so that is exactly what we do here

     void OnMouseExit()

     {

             renderer.material.color = Color.white;

     }










     //Fires off when the mouse is clicked while hovering over the object

     //Here we check if the bool was set to true or not and we load the level id not

     //or quit the application if true

     void OnMouseDown()

     {

             if(isQuit)

             {

                     Application.Quit();

             }

             else

             {

                     Application.LoadLevel(7);

             }

     }

}


Now all you have to do is change the "MonoBehaviour" to the name you are calling the script. And if you already haven't done so, go to build settings and press add current. Then go down to the bottom where it says (7) and change it to the level number shown on you build settings. This should work.

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Need Some Help regarding insert new objects in island demo 1 Answer

Mouse.Position from centre of screen? 0 Answers

How can I make accelerometer work for android? 1 Answer

[iOS Memory Question] At ~35MB of memory on a heavily multitasked iPhone4/iPad we are getting suspend-crashes after lowmemory warnings. Is there anything we can do? 0 Answers

DontDestroyOnLoad duplicate object when using a singleton 5 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