Okay, so to clean up the triangles after they've been spawned, all we need to do is we can go to our Scripts folder, create a new script. Let's call this script. Destroy. Yeah. Cool. So what we would normally do is we would normally find the position we would normally create a public very public variable for the game object position of that player.
And then we would just drag that in but because our items are being instantiated from prefabs, these different prefabs here, we can't actually do that because we'd have to drag them in and you know, and in so we're actually going to approach this in a different way. We're going to say, Private Game Object, player. And then inside of a stop method, we just want to assign the player there and we can do that easily by saying player equals game object To find game object with tag make sure it's not game objects, but game object. open parentheses, open speech quotes and capital P player. Awesome. So that will find our player.
And let's go back over to unity. Let's go to our player. And let's make sure the player is tagged with the tag player. That's definitely important. So now we the player there. Now the game knows that the player is our playoff if that makes sense, because we've tagged and back over to the script.
And then all we need to do is we need to say Well, hey, when the when something is behind the player by a certain amount, we just tend to delete that thing. So we can just run an if statement inside of update if game object dot transform Position dot z is less than player dot transfer, trance trance form dot position dot z minus 15 so that gives us a little bit of room open close parentheses open curly braces and then all we want to do is say destroy destroy destroy destroy game object cool so that will just destroy this game object whatever script This is attached to where it was whatever game object this script is attached to. It will destroy that game object when the this game object gets below 15 in the z axis of behind the plates are 15 spaces by On the player in the z axis, I hope that makes sense.
So all we need to do now is we can grab our three prefabs here. And we can add to the script, destroyer. And we can press play, and hopefully everything works out. Let's just have a look. So it looks here. Left hand things should be being deleted.
And they are things are working great. So let's just check that out in the scene view. And let's just go up player. Things look a little bit wacky because of the further we move away. Obviously, the shader works differently. But if we press play and switch this one, it's deleted.
Cool. Awesome. So that seems to be working fine. So with a simple script, we have just asked the question, Hey, are you 15 spaces behind the player And if so, just destroy that game object. And that's it. You can use for any object that will be behind the player.
And because our objects are pretty simple, and because we're not deleting them, like, not destroying them massively, like huge amounts that we're not destroying mass amounts of objects. This is actually a really fun cold to work perfectly on my bosses. It's not going to be too much of a drama and it's a really simple solution. Cool.