Handling input, movement, animation with scripts?

This is quite an open question however I think there is value to the answers to it.

So lets take a simple and common scenario, we have a player character and some NPCs all of them share the same animations, npcs move via pathfinding and the player moves via input.

Now ideally it makes sense to somehow share the animation controller and logic (i.e setting mecanim vars), the movement logic will differ so ideally the animation needs to be driven by the movement logic and the player also needs to be aware of input (be it raw keys or absracted input frameworks).

So the simplest and least flexible way to do it is to give 1 script to npcs and 1 to players which would do something like:

	transform.position += transform.forward * MoveSpeed * Time.deltaTime;
	animation.Play( "walk_cycle" );

However then there is no shared logic and if you need to change the animation names or keys etc it is a difficult job.

So I was thinking that it would be better to have some sort of eventing system so basically there would be a script to handle animation based upon movement which would be notified, so when an input happens it would notify the objects listening then when the player processes that and lets say moves forward then it raises an event of some sort for a shared animation script to listen to on each enity.

Anyway there are lots of ways to solve this problem but I wanted to see what everyone else would say is best practice on this as I find it very hard to find the unity best practices.

Here’s my java-script for movement. I think that it suits your purposes. It also holds animation code, gravity, rotation and jumping.

var speed : float = 6.0;
var twiceSpeed : float = 10.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
var rotateSpeed : float = 3.0;

private var moveDirection : Vector3 = Vector3.zero;

function Update() {
	var controller : CharacterController = GetComponent(CharacterController);
	if (controller.isGrounded) {
		//Grounded, so recalculate
		//Move directly from axes
		moveDirection = Vector3(0, 0, Input.GetAxis("Vertical"));
		//Rotation Code
		transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);
		moveDirection = transform.TransformDirection(moveDirection);
		moveDirection *= speed;
		if (Input.GetButton ("Jump")) {
			moveDirection.y = jumpSpeed;
		//Animation Code
		if (Input.GetKeyDown("w"))
			animation.Play("Full Walk");
		else if (Input.GetKeyUp("w"))
	//Apply Gravity
	moveDirection.y -= gravity * Time.deltaTime;
	//Move Controller
	controller.Move(moveDirection * Time.deltaTime);