Can't get collision working

Hello, I need to get my gameObject to sence collision with another gameObject. This is the script I am trying to use but isn’t working:

function Start (){

	particleEmitter.emit = false;

function OnCollisionEnter (hit:Collision) {

	if(hit.gameObject.tag == "ball");
	
	 particleEmitter.emit = true;  

}

If you could leave some tips on why this is not working that’d be great.

Thank you:)

This might sounds silly but have you attached the collider and rigidbody to the related gameobject?

if you have start putting Debug.Log’s in to see what is happening, but the previous post is most likely the answer.

…because you never close your Start() function?

Looking at your code I see 2 issues, the first has already been said. You have not closed your start function and the second is that the if statement you have written will check the tag, but will not emit the particle when that specific tagged object collides. It will just do it no matter what collides.

Your code should look like this. Also as previously said, make sure to have a rigidbody and collider attached to the object in question.

function Start ()
{
    particleEmitter.emit = false;
}

function OnCollisionEnter (hit:Collision) 
{
    if(hit.gameObject.tag == "ball")
    {
         particleEmitter.emit = true; 
    } 
}

Hope this helps :slight_smile:

Yeah I found that out just before I checked back here. Sorry super noob mistake.

Thanks:)