- Home /
How to remove certain parts of an object?
Attached are the actual game scene & the game scene I am currently developing. As you can see, the obstacles are created by instantiating & randomly positioning them. Parts of the obstacles are hidden behind the top part & scene. I am using second camera to show the preview/timeline of the game(top right-hand side). As you can see, it is different from the actual game scene. The hidden obstacle parts are visible in the preview. Is it possible for me to remove them? Please help.
Answer by Andres-Fernandez · Dec 09, 2014 at 07:59 AM
You can disable their renderer component and then use OnBecameVisible to enable their renderer again.
Thanks for the reply. $$anonymous$$y doubt is: the obstacle is made of 4 square elements. I am randomly arranging them to create the attached game scene. So how do I perform the method you have suggested? Could you please elaborate?
It depends on how you want your objects to appear (the whole obstacle at once or each square element at a time).
If you want each square element to appear as soon as it's visible by any camera, just attach a script to the square prefab with a reference to its renderer and use the OnBecameVisible function to enable it.
If you want the whole obstacle to appear at once (i.e. the 4 square elements) then attach a script to the parent object (the obstacle) and store a reference to the 4 children renderers. Then use the OnBecameVisible function to enable those 4 renderer references.
I think something is unclear here, which could complicate matters a little: Do the 4 squares constitute one textured gameobject, (one mesh / sprite), and you're shifting that whole thing up and down, or do you have one individual gameobject per gray square, and you're shifting each vertical collection of 4 individual gameobjects up and down?
Andres Fernandez' suggestion is based on the understanding that you've got 4 individual gameobjects per obstacle.
Spot on CHPedersen.. I have only 1 gameobject per obstacle. I am attaching the image. I am randomly moving it up & down to create the obstacles. Hence I am not sure how to remove the hidden parts of the obstacles in the game preview shown by the second camera..
Oh, sure, you're right. As you wrote "randomly arranging them" I immediately thought of Tetris-like pieces made of 4 individual sprites.
So yeah, my answer is completely useless. Feel free to downvote it, discard it or completely forget about it.