If Touching Script?

Hello. I have had trouble with making a script that closes the whole game to desktop when a certain model touches you. I already have the follow player script, I just need help on the touching or colliding script. Whatever you call it. Do you have to add other components to the models as well? Can someone please give me the script. That would be great, then I will be on my way with my project. Thanks. :slight_smile:

Attach a collider and use OnTriggerEnter() or OnCollissionEnter()

Should I attach a collider to my player and the model? Also do you know the whole script?

Im not too sure as I just started unity recently but if you attach a box collider to the player and enable trigger, then in the scriprt you can go:

void OnTriggerEnter(){
//Some script to close the game
}

Hope it helps

Ok, I know how to close the game with a script. Do you need to add a collider to the model that I need to touch?

You’re script does work, but when I touch the ground it closes the game. Is there a way to make it a certain object?

Of course, one has to have at least some kind of collider, and another has to have collider and rigidbody, then you can use method oncollisionenter.

Still can’t get it to work… :frowning:

I think theres a way that you can give a tag to an object and then check if the other objects collider is that tag.
I think its somthing like:
other.gameobject.tag == “enemy”

Also you need to assign the tag to the enemy

I tried all of that, I don’t know why it won’t work.

If anyone has the full script please tell me. Also what components to add to both enemy and player.
I keep trying but nothing is working. So if someone can do this thank you…

Never mind everyone, I just need a script that waits 20 seconds and then the application closes. Does anyone know what it is! :smile:

You can close program with “Application.Quit();” , and before that, you need to wait “yield return new WaitForSeconds(20);”

Thanks for the help, but I already found a script to make it work. :smile:

This works, but can you do it at a spesific speed?