hey i am trying to make a script where it just enables and disables certain child object of the gun
for example i want it to be like
if i have the flashlight atached to the gun then the flashlight object should appear
to atach the flashlight it should be when i press the GUI button or when a variable is = true (for item pickup)
what i have till now is this
var flashlight : GameObject;
var magazine : GameObject;
function Start()
{
SwitchAtachment(0);
}
function OnGUI()
{
if(GUI.Button(Rect(0, 0, 100, 50), “FlashLight”))
{
SwitchAtachment(1);
}
if(GUI.Button(Rect(120, 0, 100 , 50), “magazine”))
{
SwitchAtachment(2);
}
}
function SwitchAtachment(index : int)
{
if(SwitchAtachment == 1)
{
transform.GetChild(flashlight).gameObject.SetActiveRecursively(true);
}
else
{
transform.GetChild(flashlight).gameObject.SetActiveRecursively(false);
}
if(SwitchAtachment == 2)
{
transform.GetChild(magazine).gameObject.SetActiveRecursively(true);
}
else
{
transform.GetChild(magazine).gameObject.SetActiveRecursively(false);
}
}
anyone knows what the error is?
Depends. What error do you get?¨
it says that thigs that are right are wrong…
like for example
function SwitchAtachment(index : int)
it says that the “:” should be “(”
Is the spaces in the names a copy paste error or an actually issue in your script?
transform.GetChild(flashlight).gameObject.SetActiv eRecursively(false); ← right there. SetActiv:face_with_spiral_eyes:eRecursively(false);
ohh i think you solved my problem im gonna test it ty
nope its just a copy paste error