Here's one way to do it using a tweaked coroutine from the Penelope tutorial. Should be fairly easy to convert to C#. And there's probably a smarter way to restart the CheckTime().
edit Here's the code from my original response integrated with FPSWalker.js as requested. Note I think the reason you were having trouble is because I had accidentally put a lower-case "s" in start(). Start() needs to be upper-case d'oh!
@script RequireComponent(CharacterController)
var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
var delay = 10.0; // amount of time to wait before increasing speed
private var timeLeft : float;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function Start() {
timeLeft = delay;
CheckTime();
}
function FixedUpdate() {
if (grounded) {
// We are grounded, so recalculate movedirection directly from axes
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
}
function CheckTime() {
while (timeLeft > 0) {
yield WaitForSeconds(1);
timeLeft -= 1;
Debug.Log(timeLeft);
}
speed += 5; // increase character controller speed
timeLeft = delay; // reset timeLeft to 10
TimerExpired();
}
function TimerExpired() {
CheckTime(); // restart the coroutine
}
Almost forgot to answer your other question. To make your character walk forward automatically, replace this line in fpswalker.js:
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
with something like this:
moveDirection = Vector3(1, 0, 0); // moves character along the x axis
var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
private var moveDirection = Vector3.zero ;
private var grounded : boolean = false;
function FixedUpdate() {
if (grounded) {
// We are grounded, so recalculate movedirection directly from axes
moveDirection = Vector3(1, 0, 0); // moves character along the x axis