Coud public variables with same names cause problems?

I have pretty weird problem.

First i’ll explain what’s happening.

I have a character and in the MovementScript there is one function that is killing the player and moving it back to the last CheckPoint.
The function simply stops the player from moving, then deactivating only the geometries, not the whole gameObject of the character, so the scripts, can continue working. These deactivations and activations are separated by simple yields with 0.5 to 1.5 seconds.

There are holes in the game and when the player falls in them, he passes through a trigger, that simply calls the function that kills the player. It works just perfectly.

There are also characters, that shoot bullets in the game and when that bullet hits the player, it calls the same function, for killing the player. But when the bullet calls the Kill function it get’s executed just untill the first yield and then stops. So the player dissapears and doesn’t go back to the checkPoint.

There are no errors, no nothing. It just stops at the yield and happens only when bullet hits player.

The bullet have 2 public variables “speed” and “rotateSpeed”. I just found, that if i change the variable of the bullet, from speed, to bulletSpeed, the Kill function is executed untill the end.

So if i have 2 variables on completely different objects, that are public (Not Static), is that a problem???

Hmm… are you calling the kill function with some parameters? Ex. speed (which is then used in yield)? The if you make it just Kill(speed), you’re referencing speed from bullet not from the player script. It will be hard to quess without your code ;).

I had the same issue. I had two different classes, Player and Enemy, each with their own public variable “health”. I found that the enemy somehow was using the player’s health. Now I can’t speak to whether another bug was a confounding factor; however I can say that after ONLY renaming the player’s “health” variable to “playerHealth” using Visual Code refactoring tool doing NOTHING ELSE, everything worked correctly. This does not seem like correct behavior that a program’s behavior can change from the way the variables are named!