Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Collision2D on gameObject tag doesn't work SOLVED!

Discussion in '2D' started by gladiuscloud, Jan 14, 2015.

  1. gladiuscloud

    gladiuscloud

    Joined:
    Jan 11, 2015
    Posts:
    44
    1. Basically, my hero will do some stuffs like slashing the melon, but the collision doesn't work. It just passed through the melon (image below):


    2. I configured the components needed.
    Tag = watermelonTag
    Is Trigger = checked


    3. I place this code in my Hero game object.
    Code (CSharp):
    1. void OnCollisionEnter2D (Collision2D collision){
    2.      
    3.         switch (collision.gameObject.tag){
    4.  
    5.         case "watermelonTag":
    6.             srSlash.sprite = slashingSprite;
    7.             audio.PlayOneShot(swordSound);
    8.             audio.PlayOneShot(fruitSmashing);
    9.             Destroy(collider.gameObject);
    10.             break;
    11.         case "pineappleTag":
    12.             srSlash.sprite = slashingSprite;
    13.             audio.PlayOneShot(swordSound);
    14.             audio.PlayOneShot(fruitSmashing);
    15.             Destroy(collider.gameObject);
    16.             break;
    Thanks :))
     
  2. BlaXun

    BlaXun

    Joined:
    Jan 8, 2015
    Posts:
    52
    gladiuscloud likes this.
  3. gladiuscloud

    gladiuscloud

    Joined:
    Jan 11, 2015
    Posts:
    44
    BlaXun likes this.
  4. BlaXun

    BlaXun

    Joined:
    Jan 8, 2015
    Posts:
    52
    I just started with unity a week ago :)
    Had a lot of fun since then.
    I highly recommend to check the Live Tutorial Sessions each Monday...they r awesome and helped me a lot!
     
  5. gladiuscloud

    gladiuscloud

    Joined:
    Jan 11, 2015
    Posts:
    44
    OK! awesome thanks!