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 Cobrryse · Mar 01, 2014 at 03:24 PM · 2dprogramming2d collision

Infinite Runner Live Training 2d collisions not working

At about 30 minutes into the Infinite Runner Live Training, Mike used a quad to make a 2d Collider to pause the game. I copied the code word for word I'm pretty sure, but the game still doesn't pause. I have been looking over my project for about half an hour now trying to figure out what went wrong, but couldn't find anything. I would appreciate if anyone could tell me what I am doing wrong. Thanks and here's my code.

 using UnityEngine;
 using System.Collections;
 
 public class DestroyerScript : MonoBehaviour {
 
     void OnTriggerEnter2d(Collider2D other)
     {
         if(other.tag == "Player")    
         {
             Debug.Break ();
             return;
         }
 
         if(other.gameObject.transform.parent)
         {
             Destroy (other.gameObject.transform.parent.gameObject);
         }
         else
         {
             Destroy(other.gameObject);
         }
     }
 }
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 Cobrryse · Mar 01, 2014 at 06:19 PM 0
Share

Bumpity bump

avatar image Cobrryse · Mar 01, 2014 at 06:45 PM 0
Share

Here's the link to the live training session: http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/infinite-runner

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by serenefox · Mar 01, 2014 at 09:01 PM

Since it seem nobody else is answering this question I guess I will give it a try.

I looked at the video and I noticed two things that could potentially be a problem.

  1. Your code looks like it would work but since I am not as experienced in it I'm not sure, but the code in the video did not have "return;" in the first if statement.

And 2. Is your player character tagged "Player" in the inspector? And if so does the object to collide have the collider marked as a trigger?

Comment
Add comment · Show 6 · 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 Cobrryse · Mar 01, 2014 at 11:06 PM 0
Share

I am pretty sure he included the return to get rid of some $$anonymous$$or error. And yes, I am sure I tagged the character "Player". Have you tried this code yourself?

avatar image serenefox · Mar 02, 2014 at 12:11 AM 0
Share

I have not tried it myself but I am thinking I should, I will get back to you on it. But I do want to ask, are you following to tutorial exactly with all the same assets, or are you implementing this in your own game/project with your own assets? And one more thing you could try in the mean time, put this in the first if statement to see if your character is registering a hit with the collider/trigger.

 print("hit");

if nothing shows up in the console when trying the problem it will narrow things down.

avatar image serenefox · Mar 02, 2014 at 01:00 AM 0
Share

So I have tested the script and it worked as it should for me, which means its not a scripting error. I have a few things to ask you:

Does your character have a rigidbody2D on it?(Im sure its on there but I just needed to ask)

and

When I was recreating the problem and I created the "Quad" primitive, I noticed the Quad starts with a $$anonymous$$esh collider, and if its going to work it needs a 2d collider, which the mesh collider is not i don't believe. So I added the "BoxCollider2D" and removed the mesh collider. But other than that, I did not do anything differently.

I don't know what else to try, but let me know if these two questions are true, and if you are still having a problem try the print method and let me know if the console shows anything.

avatar image Cobrryse · Mar 02, 2014 at 01:53 AM 0
Share

All right. I'll get back to you in just a bit.

avatar image Cobrryse · Mar 02, 2014 at 02:12 AM 0
Share

So here's what I have

  1. I am using the sample assets that were used in the video

  2. $$anonymous$$y character does have a rigid body 2d

  3. When I put print ("hit") in the first if statement nothing prints out in the console on run

  4. I am using a box collider 2d on both destroyers, not a mesh collider.

I wanted to ask what your z axis is for the destroyers, main camera, and player and if your character is on a different layer than the rest of the project. Don't know if either of those are causing the problem. In the meantime I'll look at the vid again.

Show more comments
avatar image
0

Answer by Cobrryse · Mar 02, 2014 at 02:01 PM

I got it Serenefox! Not sure what I did, I just started from scratch and watched the video again. Thanks for sticking with me throughout it all! Owe you big time!

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 serenefox · Mar 02, 2014 at 06:20 PM 0
Share

Good Im glad it worked out, good luck with it!

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

21 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

Related Questions

Multiple Cars not working 1 Answer

Player movement script for a stickman 1 Answer

Idle Animation Not Playing 1 Answer

2D Collision Between Two Objects 1 Answer

How to generate different diagonal platforms? 0 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