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
1
Question by Brenna · Feb 01, 2012 at 12:53 AM · triggerfirst person controllerbox collider

How to change scenes using box collider and first person controller?

I have a simple scene with a cube in the middle. I want to make it so that when my first person controller runs into the cube the game will automatically transition to the next level.

I made the cube a box collider and checked "is trigger"

I made this script:

 var target : Collider;
 
 function OnTriggerEnter(cubeTrigger : Collider)
 {
 if (cubeTrigger == target)
 
 { Application.LoadLevel ("longhouserealm"); 
 
 }
 
 } 

and attached it to the cube. (longhouserealm is the name of the scene that i want to go to)

Under the cube's trigger script window, I assigned the First Person Controller as the target.

I have both of the scenes in my Build Settings list.

Buttttt it doesn't work. When i walk through the cube, nothing happens. The only thing that changed is that the cube is now penetrable instead of solid.

I've been trying to figure it out by patching together tutorials all day... I'm a newbie and would appreciate any advice or alternate methods for changing scenes!! Thank you!!!!!

Comment
Add comment · Show 1
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 syclamoth · Feb 01, 2012 at 01:20 AM 0
Share

Is your firstPersonController a characterController? Because those don't use physics.

1 Reply

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

Answer by AlucardJay · Feb 01, 2012 at 01:19 AM

i would suggest start using tags. you can have different trigger events based on the name of the tag. Click on your prefab/object door . In the Inspector at the top you should see Tag with a drop-menu next to it (possibly saying Untagged). Click on dropbox, at the bottom Click on Add Tag ...

In the Tag Manager, expand the Tag menu (click bkack arrow). In the next empty space, add your tag.

i.e. if there is no writing next to Element 0, click on it and write Door .

OK so you made a new tag , now you have to put it on the door. again click on door prefab/object. now in the inspector click on tag, now Door should be on the list. Click on it, the door should now have the tag Door.

Use this in your OnTriggerEnter function :

 function OnTriggerEnter (cubeTrigger : Collider)
 {    
     Debug.Log ("OnTriggerEnter : cubeTrigger.tag = " + cubeTrigger.tag); // shows the tag of the trigger
     // if tag is door
     if (cubeTrigger.tag == "Door")
     {
         Application.LoadLevel ("longhouserealm"); 
     }
 }
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 AlucardJay · Feb 01, 2012 at 01:31 AM 0
Share

if you have the same script running on different scenes (with the player), you are going to need lots of door tags (to load the right scene) . i.e.

 if (cubeTrigger.tag == "DoorToRealm")
 {
     Application.LoadLevel ("longhouserealm"); 
 }
 
 if (cubeTrigger.tag == "DoorToHut")
 {
     Application.LoadLevel ("hut"); 
 }
 
 if (cubeTrigger.tag == "DoorToCastle")
 {
     Application.LoadLevel ("castle"); 
 }
avatar image Brenna · Feb 01, 2012 at 02:16 AM 0
Share

great thank you, it's working now! thanks for such a detailed response!!

avatar image gamegirl1984 · Nov 04, 2014 at 04:02 PM 0
Share

I'm kinda new to this website and not sure if I'm suppose to be asking this here! So sorry in advance if I'm not!!!! I'm trying to do this SA$$anonymous$$E thing and its not working. No matter what script I use. I have a box collider set up so that when my character runs into it would switch scenes... but he just walks right through, nothing happens. if someone could help me with script? my box collider is set up on a "cube". my scene I want to change to is called "darkwoods" and my character is called "Player". I have my trigger box checked. I tagged my cube as cube and my Player as Player... I do not have a rigitbody. I did add a capsule as my character by the camera and tried that but still luck.

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

Animation triggered by an animation? 1 Answer

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

A trigger is activating scripts of other triggers 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

How Activating a boolean fron another script(C#) 1 Answer


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