How can I add an else statement to this function? Nothing I do seems to work.
function attack ()
{if (!CanSeeTarget ())
return;
for (var child : Transform in transform) {
child.gameObject.SetActive(true);
}}
How can I add an else statement to this function? Nothing I do seems to work.
function attack ()
{if (!CanSeeTarget ())
return;
for (var child : Transform in transform) {
child.gameObject.SetActive(true);
}}
If you’re starting out, i suggest you put Brackets Everywhere. (I’m exaggerating, but don’t leave them out unless you know exactly what you’re doing). You should stay with a proper formatting in order to keep your code clean and readable.
EDIT : Aight, Now that I have more info, this is what it should look like :
function attack ()
{
if (CanSeeTarget())
{
for (var child : Transform in transform)
{
child.gameObject.SetActive(true);
}
}
else
{
for (var child : Transform in transform)
{
child.gameObject.SetActive(false);
}
}
}
And actually, if you’re gonna iterate through all transforms anyway, you can actually do it like this :
function attack ()
{
for (var child : Transform in transform)
{
child.gameObject.SetActive(CanSeeTarget());
}
}
But it’s probably better to keep the first one, cause there’s probably more logic that could happen in the statements