- Home /
How to not have a function affect a prefab?
So I have a tree that drops three different colored apples and I have this Apple.script that destroys each fruit that hits a y-position of -20. This is done by calling an AppleDestroyed function that is in another script that keeps track of baskets that you catch the apples in. Everytime an apple is missed, one basket (out of three) is removed, all the spawned apples are deleted, and the tree starts dropping apples again. I have a green apple that subtracts points from your score, so the player obviously wants to not catch those but my code removes a basket whenever any apple misses the baskets. Any suggestions to how I can have the green apples miss the basket, get deleted, but not remove a basket? Thanks.
Answer by xxmariofer · Jan 19, 2019 at 10:41 PM
Whats the exact different in each apple? Just put inside the Update just after the destroy(this.gameobject) an if and make sure you only call the appledestroyed method if the apple isnt green (not sure if yyou are using a tag or color or something for it)
I'm using tags: GoldApple, GreenApple, and Apple (which is a red one). Thanks, I'll try to make that if statement.
Answer by mar10 · Jan 19, 2019 at 11:21 PM
use object pooling & just teleport the apples back to their starting positions rather than create & destroy which is hefty on the hardware don't delete the baskets just disable them so they do not render it will make your game run faster. create another script for the green apples that just subtracts the score but does nothing else.
Your answer
Follow this Question
Related Questions
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Prefab Script List not being assigned as unique - can you see why? 1 Answer
Using similar to GameObject.FindObjectsWithTag but for tag.contains. 0 Answers
How do I move one of many instantiated gameobjects ONLY if it's currently selected in a list? 1 Answer
Reinitialize prefab 0 Answers