Create a class that can be used with operators? RRS feed

  • Question

  • In the Unity Game Engine, they have classes for Vector2/3.

    With these classes you can use the basic operators on them. So instead of having a function like

    "Vector3 Add(Vector3 v1, Vector3 v2){//Add the vectors}"

    You can just do

    "Vector3 v3 = v1 + v2;" or "Vector3 v2 = v1 * 0.5f;"

    How do I create classes that can use operators? I'm guessing you have to write a function a certain way, although I'm not too sure on the terminology for this, so google hasn't been any help.


    Sunday, July 1, 2018 12:22 AM


All replies