my switch weaopns script isnt working it keeps giving me this error please help:
Prefab GameObject’s can not be made active! (secondary)
UnityEngine.GameObject:set_active(Boolean)
SwitchWeaponsScript:Main() (at Assets/GunScripts/SwitchWeaponsScript.js:9)
and here is my script:
`var primary : GameObject;
var secondary : GameObject;
if(Input.GetKeyDown(“1”));
primary.active = true;
secondary.active = false;
if(Input.GetKeyDown(“2”));
secondary.active = true;
primary.active = false;
`
Your problem is that you’re trying to activate/deactivate a prefab, instead of an instance of that prefab.
var primary : GameObject
If I’m right, you’ve assigned your primary weapon prefab to this variable from Inspector.
As I’ve said in my first sentence, activating/deactivating prefabs isn’t what you want to do.
Assign your primary/secondary weapon object which is in the scene hierarchy to your variables, NOT primary/secondary weapon objects in the Project folder.
Your if statements should look like this:
if(Input.GetKeyDown("1")){
primary.active = true;
secondary.active = false;
}
if(Input.GetKeyDown("2")){
secondary.active = true;
primary.active = false;
}