Search Unity

Unity Learn > Scripting > Intermediate > Overriding

Discussion in 'Community Learning & Teaching' started by kdubnz, Jul 31, 2019.

  1. kdubnz

    kdubnz

    Joined:
    Apr 19, 2014
    Posts:
    177
  2. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,997
    What part? The code shown (below the video tool) for subclassing Apple to Fruit looks fine. It's a standard do-nothing example that you'd see anywhere.
     
  3. kdubnz

    kdubnz

    Joined:
    Apr 19, 2014
    Posts:
    177
    The posted code is not the same code from the lesson, it's from one of the previous lessons.\
    As I said
    >>> posted code is out of Sync with the topic.
     
  4. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,997
    Ah... yes and no. The written out code isn't from an old lesson, and is fine for the topic. You're wrong about that. But it doesn't match the code in the video.

    The "Inheritance" lesson has them match, and has Apple a subclass of Fruit. The written out code for "Overriding" extends that, by having Apple override Fruit.Chop. But the video code uses Monsters, Orcs, and overrides Yell(). Otherwise it's the same example.

    There's nothing really wrong, since both examples show the same idea. I suppose they should match. Of course, neither shows why you'd want virtual functions. Showing how they work is the easy part.