Spawn GameObject when the player touches an obstacle

I have followed the brackeys tutorial on breaking an object. He uses Instantiate to spawn the Cracked version of the object and destroys the original version.
What I am doing is similar, when the player touches the obstacle, I want the obstacle to break.
There are many obstacles in my scene, do I have to create a script for every single one? That is a lot of work. I’m sure there is another way to do it.
I already have the cracked version of the obstacle(prefab). Also, I want to create a method and be able to call it in other scripts and I only want the obstacle that the player touches to break.
Thank you:)

Nope. Just create one script, and put it on all of the breakable objects. Better yet, turn the breakable object itself into a prefab, and simply place instances of the prefab around your scene.

If so, how do I specify which object I want to break when I call the method?:slight_smile:

Add gameobject tag and call On collision method

You’ll be inside the OnCollisionEnter or OnTriggerEnter method of the particular object that will be breaking. So it will just be “this”.

Thank you guys, my problem is solved;)