What is arg0?

Please could someone explain this code:
What do the 1st and 2nd line of code mean? Also, what is arg0, args?

for (int i = 0; i < comboButtons.Length; i++)
{
if (arg0.interactableObject.transform.name == comboButtons[i].transform.name)
{
userInputText.text = i.ToString();
}
}

Look at the definition of the method. It will tell you what the type of arg0 is.

It is the 0arameter being passed into whatever method this code is in.

I couldn’t understand the definition. Please could you explain this code what is happening here:

for (int i = 0; i < comboButtons.Length; i++)
{
if (arg0.interactableObject.transform.name == comboButtons[i].transform.name)
{
userInputText.text = i.ToString();
}
}

You’re missing code here. You need the function definition

This is the code. Please could you explain

private void OnComboButtonPressed(SelectEnterEventArgs arg0)
{
for (int i = 0; i < comboButtons.Length; i++)
{
if (arg0.interactableObject.transform.name == comboButtons[i].transform.name)
{
userInputText.text = i.ToString();
}
else
{
comboButtons[i].ResetColor();
}
}
}

So, arg0 is of type SelectEnterEventArgs. So it has a property called intractableObject.

When a button is pressed, it calls OnComboButtonPressed and gives it some argument called arg0 (you can change the arg0 bit to something more meaningful, though, like selectEnterArg).
The explanation is in the code

private void OnComboButtonPressed(SelectEnterEventArgs arg0)
{
    // Loop through each button
    for (int i = 0; i < comboButtons.Length; i++)
    {
        // check if the button we pressed is the button we are currently looping over
        if (arg0.interactableObject.transform.name == comboButtons[i].transform.name)
        {
            // if it is, set userInputText equal to the index of the button
            userInputText.text = i.ToString();
        }
        else
        {
            // if it's not, reset the button we are currently looping over's color
            comboButtons[i].ResetColor();
        }
    }
}

@Ninano I’m getting the feeling that the nature of the questions you’re asking means you’ve never used C# or Unity before or are relatively new. The VR course is definitely not a beginners course and little or no explanation of the C# is given as you are expected to know these things. I would recommend taking the 2D and then 3D Unity courses first before attempting this course. These will give you a better understanding of C# and Unity as a whole and put you in a better place to follow this course.

1 Like

This makes things clear. Thank you.

I have taken C# courses before and have done programming. But so many new concepts seem to be introduced in this AR VR course which makes things confusing. Please could you share the links for the Unity 2D and 3D courses that you have mentioned.

They are available here: GameDev.tv

Privacy & Terms