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 StephanieLangley · May 01, 2015 at 01:20 AM · c#triggercollidersontriggerenterloadlevel

Application.LoadLevel ("lower") loads on start-up, not when triggered; Deadline is soon HELP!

When running my game my level should be switched when the player entered a cube. However, my new scene is loaded when game is started. I have this code attached to my cube;

using UnityEngine; using System.Collections;

public class LevelTrigger : MonoBehaviour { void OnTriggerEnter(Collider other) { if (other.tag == "Player") { Application.LoadLevel ("lower"); } }

 void update(){
 }

 void start() {    
 }

} Can anyone give me any hints as to why it is doing this? I am using the Oculus Rift if this helps. Thankyou!

Comment
Add comment · Show 15
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 Bonfire-Boy · May 01, 2015 at 11:40 AM 0
Share

Is it going straight into that "lower" scene or is it loading the scene you want to be first and then changing scene? (and how do you know?)

If the latter, is it because that OnTriggerEnter() function is being called?

avatar image StephanieLangley · May 01, 2015 at 12:26 PM 0
Share

Im not sure I have changed my code to this now and when walking through the cube nothing happens. Im at a bit of a deadend here as im unsure if its even calling it at all! If it helps I am using the Oculus OVRplayer prefab for my user controller

using UnityEngine; using System.Collections;

public class LevelTrigger : $$anonymous$$onoBehaviour { bool cubeupdate = false;

 void OnTriggerEnter(Collider other) {
     if (other.tag == "Player") { 
         cubeupdate = true;
     }
 }

 void update(){
     if (cubeupdate == true) {
         Application.LoadLevel ("lower");
     }
 }
 

}

avatar image Bonfire-Boy · May 01, 2015 at 12:36 PM 0
Share

Are you calling that update() function yourself somewhere? If you want it to be called automatically by the engine you need to change its name to Update().

And if you want to know if/when the OnTriggerEnter function is being called, just add some logging to it.

avatar image StephanieLangley · May 01, 2015 at 12:53 PM 0
Share

Ive updated it and now its loading the first level immediately again. When adding logs it seems that it automatically runs the ontriggerenter method and the update method as soon as it runs the game.

avatar image hbalint1 · May 01, 2015 at 03:48 PM 1
Share

I only can think of your colliders are way too large, maybe 20x bigger than player object, so it still collides when they far away from each other. don't just lift them up. try to pull your cube way out of the map like -1000 Z position, and AFTER stat your game.

Show more comments

3 Replies

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

Answer by hbalint1 · May 01, 2015 at 04:01 PM

I only can think of your colliders are way too large, maybe 20x bigger than player object, so it still collides when they far away from each other. don't just lift them up. try to pull your cube way out of the map like -1000 Z position, and AFTER stat your game.

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 TeohRIK · May 01, 2015 at 03:49 AM

I think you need check your built setting, maybe is your "lower" Scene are set to first running scene, example below. The program will always run the first scene which is 0 that you set in the build settings, to solve that maybe you try to hold and drag your "lower" scene to other number beside of 0

alt text


untitled.png (61.0 kB)
Comment
Add comment · Show 3 · 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 StephanieLangley · May 01, 2015 at 07:55 AM 0
Share

This is the build settings I currently have. Im struggling to find the answer to this because it seems as if it should be working fine

capture.png (45.3 kB)
avatar image Fappp · May 01, 2015 at 02:42 PM 0
Share

You could try Application.LoadLevel(1)

avatar image StephanieLangley · May 01, 2015 at 03:32 PM 0
Share

I've already tried this, thank you anyway! Still just loads automatically on start up!

avatar image
0

Answer by $$anonymous$$ · May 01, 2015 at 06:56 PM

I think:

     void OnTriggerEnter(Collider other) //When the Object with the tag "Player" Enter it's trrigger
     {
         if (tag == "Player")
         {
             Application.LoadLevel("lower")
         }
     }
 
     void OnTriggerStay(Collider other) //When the Object with the tag "Player" Stay in it it's trrigger
     {
         if (tag == "Player")
         {
             Application.LoadLevel("lower")
         }
     }
 
     void OnTriggerExit(Collider other) //When the Object with the tag "Player" Exit it's trrigger
     {
         if (tag == "Player")
         {
             Application.LoadLevel("lower")
         }
     }


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

6 People are following this question.

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

Related Questions

how can i load a scene when reaching certain score? Roll-a-Ball Project 1 Answer

Distribute terrain in zones 3 Answers

Make object react to certain triggers only 1 Answer

Where is this (-1) coming from in my change level script? 1 Answer

OnTriggerEnter() and OnTriggerExit() called multiple times despite checks. 3 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