here’s my code
void Update()
{
if (Time.time > targetCont)
{
Destroy(gameObject);
health.healthX--;
}
}
here’s my code
void Update()
{
if (Time.time > targetCont)
{
Destroy(gameObject);
health.healthX--;
}
}
I don’t understand your problem.
But i think you should move “Destroy(gameObject);” at after “health.healthX–;”
@kinguhdahood5
Never use GameObject.Find() or any variation of it for anything outside of prototyping, and thus please dont teach people to use it in their code. It’s slow and scales horribly with project size. And it never ever has to be used.
If OP was talking about removing HP and the bullet after it hit a player, the best way to do this would be to check OnCollision, and if the collided object was the player, we’d get the reference through there.
However, i’m not even quite sure if this is what OP wants, since he for some reason wants to destroy the object (and reduce some health) after Time.time surpasses some predefined ‘targetCont’, of which i cant make sense.
Sorry about that, learning things new everyday, I’ll just delete the post
It’s fine, we all need to learn these things at some point. I dont think you needed to delete your post over it either. I just wanted to make sure that anybody reading it takes it as an example, knowing that in any real implementation they can and should do without Find(), since it’s a slow operation that gets even slower the bigger your project becomes.
Hope my reply was not perceived as a scolding or anything haha, it was not intended to be