Exemplo n.º 1
0
    void SetDoors()
    {
        if (north)
        {
            WallN.SetActive(false);
            DoorN.SetActive(true);
        }

        if (south)
        {
            WallS.SetActive(false);
            DoorS.SetActive(true);
        }

        if (east)
        {
            WallE.SetActive(false);
            DoorE.SetActive(true);
        }

        if (west)
        {
            WallW.SetActive(false);
            DoorW.SetActive(true);
        }
    }
    void Start()
    {
        WallE   wallE   = new WallE();
        Robocop robocop = new Robocop();

        // Calling Move() (from IRobotHelper)
        // First it will execute the shared functionality, as specified in IRobotHelper
        // Then it will execute any implementation-specific functionality,
        // depending on which class called it. In this case, WallE's OnMove().
        wallE.Move(1);
        // Now if we call the same Move function on a different implementation of IRobot
        // It will again begin by executing the shared functionality, as specified in IRobotHlper's Move function
        // And then it will proceed to executing Robocop's OnMove(), for Robocop-specific functionality.
        robocop.Move(1);
        // The whole concept is similar to inheritence, but for interfaces.
        // This structure offers an - admittedly dirty - way of having some of the benefits of a multiple inheritence scheme in C#, using interfaces.
    }