Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

(Solved) Collision happens, but is not detected?

$
0
0
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.

Viewing all articles
Browse latest Browse all 7934

Trending Articles