Search Unity

Need help with collision (2D)

Discussion in '2D' started by elvira, May 27, 2015.

  1. elvira

    elvira

    Joined:
    May 19, 2013
    Posts:
    1
    Hello,

    I'm new with Unity and I am trying to make a 'game' where objects (cats) fall and hit the ground(floor) or the 'player' (which in my case is a basket).

    When the catobject hits the floorcollisionobject, I want the catobject to be destroyed (or start at the top of the scene).

    Here are some images:
    Scene

    Floor object:


    Cat object:



    RemoveCatScript:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class RemoveCatScript : MonoBehaviour {
    5.  
    6.  
    7.     // new method
    8.     void OnCollisionEnter2D(Collision2D coll)
    9.     {
    10.         if (coll.gameObject.name == "cat01" || coll.gameObject.name == "cat02")
    11.         {
    12.             Destroy(coll.gameObject);
    13.  
    14.         }
    15.     }
    16. }
    17.  
    I can't seem to get it work.. I hope I've explained well enough what I want it to do.

    Thanks very much for reading my post.

    ~Elvira
     
  2. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    899
    Since you have "Is Trigger" checked, you will need to use OnTriggerEnter2D.