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
2
Question by Lungfish · Dec 10, 2010 at 03:14 AM · triggerchangelevels

How do I make it so that when you pass over a line, you switch levels?

I want to make it so that when you walk between two posts (made with Sketchup), you go to the next level. This is exactly what I wrote so that you can change levels

function Update () { (Application.LoadLevel (1); }

Now what do I add to make it do this when the player touches the object I want them to?

P.S. Full code would be appreciated because I'm new to unity and don't know how to write it properly.

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
1

Answer by Uriel_96 · Dec 10, 2010 at 04:04 AM

This is not how it works, what you are doing in theat script is only pass to another level, what you need to do its add the posts a collider and make it trigger and make sure the 2 objects(player and posts) have rigidbody so like that you only write this script in the posts and put the players tag = "player":

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

Note: if the posts are separated one of other make sure to put an empty object and parent the posts into the empty object and in that empty object put this script.

Comment
Add comment · Show 4 · 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 Uriel_96 · Dec 10, 2010 at 04:13 AM 0
Share

That one of $$anonymous$$C HALO its very helpful to, a little similar but its different. $$anonymous$$y script works for trigger and putting this to the posts and the one of $$anonymous$$C HALO is working with hits and its putted on the player

avatar image MC HALO · Dec 10, 2010 at 05:01 AM 0
Share

Yep that's true both will work and Uriel code does what you need it to do as well You have to good answers :)

avatar image FLASHDENMARK · Dec 10, 2010 at 06:16 AM 0
Share

You could alos use raycasting.

avatar image MC HALO · Dec 10, 2010 at 07:15 PM 0
Share

you can do :)....

avatar image
1

Answer by MC HALO · Dec 10, 2010 at 04:06 AM

Ok the first thing is make a new object resize it an place it on the floor, once placing the object on the floor Tag it Meaning in unity make a tag and add that tag to the object that you placed on the floor. I would name the tag something like "WalkedOverLevel1" A shit name thats because i can not think of anything else lol. Ok When you do that make sure you player has a character controller on him if so then create a new java script and place the following code :

function OnControllerColliderHit (hit : ControllerColliderHit){

if(hit.gameObject.tag == "WalkedOverLevel1") {

Application.LoadLevel(2);

//Or you can place the level name like so:

// Application.LoadLevel("Grave");

}

}

I prefer the second option this is because if you use the 1 2 3 etc it will cause problems later on. Say for example you moved level 1 and you created a new level before that and that level will now be level one in unity 3d. If you place the name it will load it by looking for the name rather than the numbers.

yep that's all you need to do :)

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 Given · Jan 26, 2011 at 02:00 AM

function Update (){ if(transform.position.x <= 12){ Application.LoadLevel(2); } }

Another approach: if you pass a certain point, it loads a new level (I use less than 12 X) the advantage of this is that you don't need to create any colliders or tag anything. Its also very simple.

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Load scene when colliding on GameObject 1 Answer

A trigger is activating scripts of other triggers 1 Answer

when i click the GUI button it doesnt load the level 1 Answer

Ignore collision on tag not working 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