Hello so I have a problem where I need to share variables between scripts.
I have a pistol that inherits from class Weapons and I am planning to have the different types of guns to shoot different bullets. I have a bullets that has a damage variable and I need to share that to the Enemy class so i could have that bullet deal damage to all enemies that inherit from this class is there any way I could do that, so far everything I have tried has failed.
What have you tried? How did they fail? Could we see your code?
We cannot help much unless we know what you tried so far or what your project even looks like.
Generally though you can simply put some code on the bullet itself that says “If I collide with a class that can be damage, call it’s damage() function.”
and this is the Enemy absract class which needs to use the damage on the bullet. I only have a target dummy for now which is why the Enemy class is so empty for now.
So what is it about this apprach that doesn’t work? You have a Take_damage function which at the moment takes one argument, but can take as many as you wish. I suspect that’s what you meant by “share variables”, or am I wrong?
Ok, It’s still not working you are correct, but now I notice that the problem is that it’s also not detecting the collision with objects with the Enemy class I noticed that because the bullets weren’t colliding the bullets deleted didn’t pop up in the console and after i removed the if statement that checks wether or not it’s an Enemy class it was popping up “bullets deleted” in the console so the problem might also be in the detection.
If this is purely for enemies that move around, it should probably be something like a CharacterBody3D or a RigidBody3D etc.. depending on what you need.