Scripting mod removal from gun (pref Java)

i want to remove a silencer or scope from a gun using a script. the meshes are a separate part of the gun. i don’t have the animation yet but for the time being would just like to remove the item from the scene and then have it replaced when i press the key. what would be the best way to go about this?

Turn the renderer on and off would be the best till you have the animation.

if(renderer) {
renderer.enabled = false;
}

i am using this to get it to disappear but i cannot get it ro reappear. am i missing some sort of check as to whether the render is at a stare of true or false.

if (Input.GetKeyDown(“r”)){
renderer.enabled = false;
}
if (Input.GetKeyDown(“r”)){
renderer.enabled = true;
}

Try

var tog : boolean;

// May need GetKeyDown for toggle

if(Input.GetKey(“r”)) {
tog = !tog // Toggle
}

if(tog) {
renderer.enabled = true;
}
else if(!tog) {
renderer.enabled = false;
}