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 AcidDreamer · Mar 22, 2013 at 09:59 PM · detectcolissiontouching

how to detect if one object is touching another

I want to change levels..So everytime that the player touches the EndLevel point it will start another level..

this is what i've come to so far

 function OnCollision(col : Collision) {
     if (col.gameObject == "Player" ) {
         Application.LoadLevel (1);
     }
 }

But it doesn't seem to work , i get no errors , yet nothing is happening in the actual game.

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 Owen-Reynolds · Mar 23, 2013 at 12:49 AM 0
Share

"i get no errors": ins$$anonymous$$d of giving errors, javaScript will often just skip the line, or guess what you might have meant.

$$anonymous$$issing ".name" would give a "can't compare these" error in C#. Oddly, missing the ENTER after OnCollision isn't technically an error, so you always have to double-check those.

4 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Alzander2001 · Mar 27, 2015 at 03:16 PM

This is what i used for the next level portal:

 void OnTriggerEnter2D(Collider2D other)
 {
     if(other.gameObject.tag == "Player")
     {
         DontDestroyOnLoad(other.gameObject);
         Application.LoadLevel("ENTER LEVELNAME HERE");
     }
 }


This is C# and sorry about that. You must also tag the player as "Player". What this is doing is running this function whenever anything touches it, and if the tag is "Player" it will load the selected level.

P.S If you have a 3D game, just Change "OnTriggerEnter2D" to "OnTriggerEnter", and change "Collision2D" To "Collision".

Thanks! -Alec

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 Wrymn · Mar 22, 2013 at 10:18 PM

You need to write it like this:

 function OnCollisionEnter(col : Collision) {
     if (col.collider.name == "Player" ) {
         Application.LoadLevel(1);
     }
 }

or if you want to use it with TAG:

 function OnCollisionEnter(col : Collision) {
     if (col.collider.tag == "Player" ) {
         Application.LoadLevel(1);
     }
 }
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 cgeopapa · Oct 27, 2014 at 06:47 PM 0
Share

I know it's been a while since this topic was active, but I hope someone will see my question:

When you write: col.collider.name == "Player" Witch name do you write? The gameObject's name?

avatar image
0

Answer by BPR · Mar 22, 2013 at 10:07 PM

Hi, you are comparing a gameObject and a string, try to use col.gameObject.name or col.gameObject.tag instead

Regards, BPR

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 AcidDreamer · Mar 30, 2013 at 10:41 AM

Thanks both for your answers.. It seems I cant set the unity correctly to behave according to the script...What I basicly did was adding this script to the a cube i wanted to use as a winpoint.. But when the player touches it , nothing happens

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

14 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

Related Questions

how to get objects that are in some radius with the point in certain center 1 Answer

How to reach multiple GameObjects' value , enemy AI 1 Answer

Is it possible to detect console prints? 1 Answer

gameObject A detecting keyboard inputs from gameObject B. 1 Answer

detect 360 spin on mobile device 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