How to extend a function from another script

I’m trying to make a generic script to be used by many game objects. I’m first creating a base class from which I derive the other scripts. For example:

using UnityEngine;
using System.Collections;

public class BaseEnemyBehavior : MonoBehaviour {
	void Update () {
		move();
	}
	
	void move(){
		transform.Translate(Vector3.forward);
	}
}

Then I want to be able to extend this Script and only modify the function move() to get the same behavior but with different movement. I’m doing this, which doesn’t work. (This would be in another script in a different object).

using UnityEngine;
using System.Collections;

public class DerivedEnemyBehavior : BaseEnemyBehavior {
	void move(){
		transform.Translate(Vector3.back);
	}
}

Could anyone point me in the right direction? I’m reading the MSDN docs for Inheritance but I’m not able to translate that into Unity.

Well it’s exactly the same in Unity as in any other C# - you are looking for polymorphism - see here: http://msdn.microsoft.com/en-us/library/ms173152(v=vs.80).aspx

Basically move needs to be declared virtual in the base class and then either public or protected.

    protected virtual void Move()  //Methods should begin with capital letters
    {
    }

Then in the derived class:

    protected override void Move()
    {
          //Whatever
          base.Move(); //Optionally call the base class implementation
          //Other code
    }

In your case though, if you are just changing Update you can just write an Update function in the derived class and call the base class if you wish (so long as it is public or protected). In this case you define it with the New keyword - this is something that Unity lets you do that is kind of different in normal .NET

    protected void Update()
    {
         //Base class functionality
    }

Then in the derived class:

    protected new void Update()
    {
         base.Update();
    }