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 KravenArk · Jun 26, 2015 at 08:16 PM · assetloadlevelcollison

Collision To Next Level Is Not Working

 #pragma strict
 function OnCollisionEnter(collision: Collision) {
   if (collision.gameObject.tag == "Exit"){
           Application.LoadLevel ("Level_2");
   }
 }


the idea of this code is to have my player hit the cube(which is tagged "Exit"), and then the game will switch to another level called Level_2

The problem is the collision just doesn't work. My script is attached to my player which is the standard first person controller.

Comment
Add comment · Show 2
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 Lahzar · Jun 26, 2015 at 08:49 PM 0
Share

It should work as long as you make sure your cube has a mesh collider and that your loadlevel function is working. What I would do is: make the cube a trigger and put this script on it:

 function OnTriggerEnter(col: Collision) {
     if(col.tag == "Player" || col.gameObject.name == "First Person Controller") {
         Application.LoadLevel("Level_2");
     }
 }


I have not tested this, and JavaScript isn't exactly my field of expertice. So here is the C# version. Just put it on your exit.

 void OnTriggerEnter(Collider c) {
     if(c.tag == "Player")
         Application.LoadLevel("Level_2");
 }

If this doesn't work you could try OnTriggerStay. And if that doesn't work either, something is definently wrong with the cubes collider or the scene youre trying to load!

avatar image KravenArk Lahzar · Jun 26, 2015 at 09:00 PM 0
Share

okay ill try all 3 things that you suggested then ill tell you ow they go

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KravenArk · Jun 26, 2015 at 09:08 PM

The cube has a box collider on it so that isn't an issue. I couldn't use the first script because I got this error "Tag is not a member of UnityEngine.Collision" The second script had no effect. I'm attaching my scene so you can see for yourself. http://www.filedropper.com/colliderdoesntwork

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 Lahzar · Jun 27, 2015 at 09:47 AM 0
Share

Change col.tag to col.transform.tag or something like that. Anyways; I got some time to test it now. If you want the script to be on the player, you can simply use OnControllerColliderHit! Here is a C# sample that I've tested and it works:

 using UnityEngine;
 
 public class Trigger : $$anonymous$$onoBehaviour {
     void OnControllerColliderHit(ControllerColliderHit other)    {
         if(other.collider.tag == "Exit")
             Application.LoadLevel("Test");
     }
 }

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

22 People are following this question.

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

Related Questions

How can I load a level when health depletes to 0? 1 Answer

How to delete a Tile on Collision ? 0 Answers

Dynamic Asset loading? 6 Answers

How NOT to create redundant materials with new names on import? 2 Answers

Why Are My Project Assets Constantly Re-Importing? 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