- Home /
Need Help Fixing WeaponScript *(cant find compiler error)
Thanks in advance3 guys!
heres my script:
function Start()
{
SwitchWeapon
}
function Update()
{
if(Input.GetKeyDown("1"))
{
SwitchWeapon(0);
}
else if(Input.GetKeyDown("2"))
{
SwitchWeapon(1);
}
else if(Input.GetKeyDown("3"))
{
SwitchWeapon(2);
}
}
funtion; SwitchWeapon(index : int)
{
for(var i=0; i<transform.childCount;i++)
{
if(i==index)
{
transform.GetChild(i).gameObject.SetActiveRecursively(true);
}
else {transform.GetChild(i).gameObject.SetActiveRecursively(false);}
}
}
Try changing
function Start()
{
SwitchWeapon
}
to
function Start()
{
SwitchWeapon(0);
}
and remove the ; after funtion in line 22
Also the error gives you the exact line in which the error occurs.
SetActiveRecursively is deprecated. Use SetActive ins$$anonymous$$d.
Answer by Langynom · Mar 17, 2013 at 02:27 PM
The first error I notice is line 22 "funtion;" First of all it should be 'function' second You don't need the ';' in there. Secondly in the start function if you are trying to call the SwitchWeapon function it should be 'SwitchWeapon(0);'
Finally where you have:
for(var i=0; i<transform.childCount;i++)
I'm pretty sure it should be
for(var i=0, i<transform.childCount, i++)
I may be wrong on that last one though. Out of interest what is it you are trying ot accomplish with this? There may be a better way to do it.
Those are the ones that jump put at me, try that and let me know if your still getting errors, for future reference if you get any syntax errors clicking on the notification at the bottom of your screen in unity should give you more details on where/how to fix them.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
GUI cale and position according to the actual screen resolution. 1 Answer
Raycast Destroys player. 1 Answer
climbing ladders script, help 0 Answers
C# Reload Script 1 Answer