Hi, I have been working on a trigger detection system, in the moment that the player passes through a trigger his gun gets activated and it works fine, but when I have to players in scene both of the player get their guns active, even if just one of them enters the trigger.
How can I make so that the trigger only activate the components of the player that passes through it?
function OnTriggerEnter(col : Collider)
if (col.gameObject.name == "Minigun_Trigger")
Gun_Script.minigunUnlocked = true;
RocketLauncher.rocketsUnlocked = false;
SmokeCreator.smokeUnlocked = false;
Gun_Script.minigunUnlocked = false;
You need to not use static variables - statics are for advanced use only and always cause this kind of behaviour if you use them without careful planning. (See this article)
In your case you will need a way of accessing the Gun_Script, RocketLauncher etc for the particular player - if they are scripts on the player (and the script you posted is attached to the player) then you should just be able to make them non-static and then get access using GetComponent.
GetComponent(Gun_Script).minigunUnlocked = true;
Don’t use static variables to unlock the weapons. These belong to the class, not to the individual members of that class, and thus there is only ever one single instance of that variable.
Use public variables and access them via GetComponent();