Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 smasgames · May 31, 2011 at 02:15 PM · collisionloadlevelon

load level on collision

how can i reload the last level when i collide with the wall

Collision picture: http://2.bp.blogspot.com/-SJx6M6L-f14/TeT5XKrEuPI/AAAAAAAAAAQ/r68csxwh2ik/s1600/Screen+shot+2011-05-31+at+15.09.40.png

at the moment i can't do anything

Comment
Add comment · Show 3
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 smasgames · May 31, 2011 at 11:04 PM 0
Share

save it does nothing

avatar image save · May 31, 2011 at 11:06 PM 0
Share

Is your wall named "wall"? Have you applied the code to the player? The name is just an example, you could also use tags ins$$anonymous$$d (which would be to prefer probably).

avatar image smasgames · Jun 01, 2011 at 12:59 AM 0
Share

Yes it's a game object with cubes that are sized to look like a wall, as the child objects.

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by save · May 31, 2011 at 02:35 PM

 function OnCollisionEnter (collision : Collision) {
     if (collision.gameObject.name=="wall")
         Application.loadLevel(Application.loadedLevel);
 }
Comment
Add comment · 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 qwertyk31 · Aug 19, 2013 at 08:10 AM 0
Share

cant get this to work. The script is added to a cube but when the First Person Controller runs into it nothing happens

 function OnCollisionEnter (collision : Collision) {
     if (collision.gameObject.name=="First Person Controller")
         Application.loadLevel(2);
 }
avatar image save · Aug 19, 2013 at 08:31 AM 0
Share

For the character controller you would use OnControllerColliderHit().

 function OnControllerColliderHit (hit : ControllerColliderHit) { 
      hit.gameObject.Send$$anonymous$$essage("Collision$$anonymous$$essage", hit.gameObject.GetInstanceID());
 }
 
 // The objects to collide with must have receivers:
 function Collision$$anonymous$$essage (id) {
      if (id == gameObject.GetInstanceID()) {
           Application.loadLevel(Application.loadedLevel+1);
      }
 }

avatar image qwertyk31 · Aug 19, 2013 at 08:44 AM 0
Share

tried figuring this out by myself but couldn't find out what is a receiver and how do i add them

avatar image save · Aug 19, 2013 at 08:53 AM 0
Share

It's just a ter$$anonymous$$ology when sending a message across scripts. Create a new JS file and paste the script from my example and you should be ready to go.

avatar image qwertyk31 · Aug 19, 2013 at 09:03 AM 0
Share

Still cant get it to work I added a debug.log to the OnControllerColliderHit and that never shows up either.

Show more comments
avatar image
0

Answer by SakuraHolm3s · Oct 28, 2013 at 10:47 PM

pragma strict

private var NL = false;

function OnControllerColliderHit(hit:ControllerColliderHit) {

if(hit.gameObject.tag == "NextLevel")

{

Debug.Log( hit.gameObject.tag );

yield WaitForSeconds (3);

NL = true;

} }

function LateUpdate() { if(NL) {

 Application.LoadLevel(0);
 NL=false;

} }

be sure to set the tag right !!! (spelling also) 2: be sure to set the level you want to load to the number 0 in the build settings under file.

but ... you don't need the : yield WaitForSeconds (3);

you can use it if you want it to wait 3 seconds before loading the other level.

found at http://answers.unity3d.com/questions/39961/collision-load-level.html

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Load New Scene On Collision. 1 Answer

help with script load level on 0 enemies 2 Answers

On Collision enter the next level? Help please? 2 Answers

Using LoadLevelAsync to load a level in the background , but initiate the level changing after something is done 1 Answer

Load last scene/level 4 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