Home>

Suppose Test.cs is attached to the Player character in Unity.
The question is

Public class Test: MonoBehaviour
{
   private bool isRun = null;
   private float _walkSpeed ​​= 2.0f;
   private float _runSpeed ​​= 2.0f;
   void Update(){
      float moveSpeed ​​= isRun? _runSpeed ​​:_walkSpeed;
      Debug.Log(moveSpeed);
   }
}

What does the bold part above mean?

float moveSpeed ​​= isRun? _runSpeed ​​:_walkSpeed;

Also, what would it be if this were briefly described?

*Animator component is attached to the Player character,
In the parameter of AnimationController in that, bool is Run is set.

  • Answer # 1

    I think it is good to google with the ternary operator.

    Also, what would it be if this were briefly described?

    I wonder...

    float moveSpeed;
    if (isRun)
    {
        moveSpeed ​​= _runSpeed;
    }
    else
    {
        moveSpeed ​​= _walkSpeed;
    }

  • Answer # 2

    It's the definition of class name and function name.

    I can't describe it more easily

  • Answer # 3

    >Bold text

    Which side is it?

Related articles