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 CHU · Aug 03, 2011 at 01:02 AM · cameraloadlevel

How do I get the MainCamera to trigger application.loadLevel when it hits a collider?

Hi all,

I am working on my first game in Unity and at the start I have a camera moving around the starting area which I want to trigger the main level to begin once it gets to a specific point.

The code I am using is...

 function OnTriggerEnter (Collision : Collider)
 
 {
 
 if(Collision.gameObject.tag == "MainCamera")
 
 {
 
 Application.LoadLevel("level2");
 
 }
 
 }

I have attached this script to an EmptyGameObject with a Trigger Collider, I have animated the MainCamera to enter this trigger box at the end of its cycle. The main camera is tagged as 'MainCamera' to match the tag in the script.

When I do this nothing happens, however if I use a FirstPersonController instead, it works fine, as soon as I walk into the trigger collider the next level loads.

I do not want a FirstPersonController active though, as it is an intro camera pan where I want no interaction from the player.

I have also tried using other GameObjects to trigger the next level, but these do not activate the trigger either, it only seems to be the FirstPersonController that will trigger the next level to load when it hits the collider.

Can anyone offer any advice on this please?

Many thanks in advance.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by hockohock · Aug 03, 2011 at 01:51 AM

My first thoughts, you might want to try if(Collision.tag == "MainCamera") rather than if(Collision.gameObject.tag == "MainCamera"). An easy way to tell what is colliding with your GameObject is by print(Collision.tag) or print(Collision.name). Other than that you might want to double check the tag of the Camera and also make sure there is a collider on there.

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 CHU · Aug 03, 2011 at 02:15 AM 0
Share

Thanks for your advice, I added a Rigidbody to the camera and now it works fine. I thought a Box Collider would be sufficient, I didn't think it would need a Rigidbody aswell, but it seems it does!

Thanks for your help

avatar image
0

Answer by aldonaletto · Aug 03, 2011 at 02:25 AM

Triggers detect rigidbodies or CharacterControllers. Create any simple object - a cube, for instance - and add a CharacterController to it using Components/Physics/Character Controller menu. Child the object to the camera, and reset the object's position. Presto! Your camera will be detected by any trigger!
Don't mind about the CharacterController you've added to the camera: it's just a component, not the First Person Controller (the F P Controller is a prefab; it has its own CharacterController, and that's why it activates the trigger).

Comment
Add comment · 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 CHU · Aug 04, 2011 at 01:09 AM 0
Share

Thanks for your advice, yes adding a Rigidbody to the camera works just great!

avatar image mecha-box · Sep 14, 2013 at 06:08 PM 0
Share

Thanks for the answer. You can also add to the cube (stored as a child of the camera) a rigidbody + collider (if someone don't like to add a character controller). And don't remember to check is$$anonymous$$inematic and uncheck Use Gravity.

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

how to load random level but one? 3 Answers

Application load advanced loading NO EXPERIENCE 2 Answers

[Unity 3] Music playback stops unexpectedly when loading a new level 2 Answers

Current scene number 2 Answers

How to see what level is running? 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