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 /
This question was closed Mar 07, 2015 at 05:33 PM by FatalVitality for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by FatalVitality · Mar 07, 2015 at 03:56 PM · c#2derrorcollider

(Solved) Collision happens, but is not detected?

Hi, I'm trying to make a 2D breakout clone as an assignment, but I've ran into a problem; whenever I start the game the ball will collide with a block, and det block should be destroyed. But it does not. The ball bounces of it and back to the paddle. So I made a debug.log, but it does not show me the collision.

I get the error: MissingComponentException: There is no 'Collider' attached to the "Block" game object, but a script is trying to access it.

However, there is a boxcollider attached to the Block, as well as a rigidbody, so goes for the Ball.

Here is the BoxScript:

using UnityEngine; using System.Collections;

public class BlockScript : MonoBehaviour {

 public BlockType blocktype = BlockType.Blue;
 private int points;
 public int hp;
 private int timesHit;
 public bool doubleX = false;


 public enum BlockType{
     Blue = 1,
     Green = 5,
     Yellow = 10,
     Orange = 15,
     Red = 20,
     Black = -10,
 }

 void Start(){

 }

 void update(){
     
 }


 void OnCollisionEnter2D(Collision2D col) {
     Debug.Log (collider.gameObject.name);
            //GameManager.score += points;
     Destroy (gameObject);
 }

}

Also, changing it between OnCollisionEnter and OnCollisionEnter2D makes the error disappear, but the debug does not detect the collision, nor is the object destroyed.

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

1 Reply

  • Sort: 
avatar image
0

Answer by tanoshimi · Mar 07, 2015 at 05:05 PM

2D physics and 3D physics are handled by completely different systems and do not interact with each other.

If you're making a 2D game, you need Collider2Ds and Rigidbody2D components on your objects, and use OnCollisionEnter2D() in your code.

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 FatalVitality · Mar 07, 2015 at 05:08 PM 0
Share

They all have Rigidbody 2d and box/circle Collider 2D attached to them. Having OnCollisionEnter2D(Collision2D col) on them rather than void OnCollisionEnter(Collision col) causes the game to freeze and give me an error:

$$anonymous$$issingComponentException: There is no 'Collider' attached to the "Block" game object, but a script is trying to access it.

avatar image Eric5h5 · Mar 07, 2015 at 05:30 PM 1
Share

Because there isn't. Presumably you meant col.gameObject.name, to refer to the col variable passed into the function, not the (apparently non-existant) collider component attached the object the script is on.

avatar image FatalVitality · Mar 07, 2015 at 05:31 PM 0
Share

Yeah, you're right. Thank you!

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

Dying Script error 2 Answers

Distribute terrain in zones 3 Answers

Collision returning an error 0 Answers

Keep getting this error CS8025 1 Answer

Space opening main menu (undesired) 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