[SOLVED] 2D collision not working! :/

I understand that this is something very simple, yet I thought I already figured this way back when I was jut demoing unity; anyhow, my collision script that works in the regular version of unity doesn’t seem to work for the iphone version:

static var Count : int = 0;
var gobble : AudioClip;

function  OnCollisionEnter  (collisionInfo : Collision) {
 if (collisionInfo.gameObject.tag == "fruit"){	
	
	Destroy(gameObject);
	Count++;
	audio.PlayOneShot(gobble);

 }
}

I don’t understand why it’s not working. The objects are 2D quads with sphere colliders, as I read that mesh colliders won’t work.

i’m not sure why, but after I restarted unity everything seemed to work as it should; with the exception that the collision throws off my character… i haven’t looked into this yet so i’m doing sow now… but if anyone know’s why, I would appreciate it if you shared your knowledge on the issue.

figured it out… or atleast, this works for me. I believe that it was because of the lack of mass once the rigidbody was attached; after I set it to 1000 everything was ok.

static var Count : int = 0; 
var gobble : AudioClip; 

function  OnCollisionEnter  (collisionInfo : Collision) { 
 if (collisionInfo.gameObject.tag == "fruit"){    
    
   Destroy(gameObject); 
   Count++; 
   audio.PlayOneShot(gobble); 

 } 
}

Um?

If I’m reading that right, you’re destroying the game object that’s also playing the sound?

If you’re going to destroy the gameObject, you need to trigger the sound to play from an external source before destroying it, eg

Camera.Main.audio.PlayOneShot(gobble);
Destroy(gameObject,0);

(Forgive me if i got that wrong, i’m going by memory) :slight_smile: