- Home /
Prefabs wont disapear
Hi, i tried a doodlejump clone but the items that are beneath the player dont get destroyed i tried something like that on the itemprefab:
public gameObject Character;
void Update()
{
if (Character.transform.position.y -15f> transform.position.y)
{
Destroy(gameObject);
}
}
but it does not work...
Greetings Marcurion
Answer by funkyllama · Dec 11, 2011 at 03:58 PM
I don't mean to point out the obvious but is the difference greater than 15? But one thing I notice that is wrong with your script is public gameObject Character should be public GameObject Character. Note the uppercase G
Hi, thanks for your answer. Yes diffrence is greater than 15 and in my script GameObject is uppercase.
Greetings $$anonymous$$arcurion
Answer by Marcurion · Dec 11, 2011 at 07:01 PM
Thanks for your answer. Yes difference is greater than 15 and in my script GameObject Character has uppercase G
Greetings Marcurion
Answer by TheCodeMonkey · Dec 11, 2011 at 08:01 PM
Just using the code you gave in your question I have an object destroying when it is 15 below whatever target I give it. The problem does not appear to be in your script as it functions fine, perhaps you are linking your objects to the wrong "character" object, or they never actually get 15 below the player to be destroyed. If your objects are prefabs that are being instantiated be sure to check that they are properly linking to the character.
Try changing the distance at which they destroy to a very small number for testing purposes, whatever the problem is it is not with your script. as long as gameObject is an uppercase G that is.
Yep, that'll be it. Come on $$anonymous$$arcurion, admit it, you forgot to link your character.. We've all done it :) :). Are you getting any NULL References in your console when you run it, if so then that'll be the reason :)
Answer by Marcurion · Dec 12, 2011 at 08:44 AM
No sorry, i would be happy if that were the problem - all prefabs are properly linked. Maybe it matters that i let the prefabs spawn by another prefab...
MFG Marcurion
Answer by Marcurion · Dec 12, 2011 at 08:58 AM
Ok i found something: The problem occurs if i put the box with the script attached into the empty prefab, the link to the character gets cut, and it refuses drag and drop a new GameObject, but i can select an GameObject over the small circle menue, however the script does not work once it is in the prefab
Greetings Marcurion
Your answer
![](https://koobas.hobune.stream/wayback/20220613062001im_/https://answers.unity.com/themes/thub/images/avi.jpg)