Timer before going back to default speed ~ Help please

Hello! I’ve been trying to create a timer for my FPS.

The situation: When my FPS hit a fire orb, temporary Speed will be the default speed (otherScript.speed) + increase (5.0). However, I would like the FPS to go back to the default speed after 5 seconds. But I can’t compile my script and keep getting “Generators cannot return values.”

Here’s my script:

var Fire: GameObject;

var otherScript : FPSWalker;
var increase = 5.0;
var temporarySpeed = 0.0; 
var speedBoostDuration = 4;
var nextActivationTime = 0.0;

private var timer = 0.0;
private var horizontalSpeed = Input.GetAxis("Horizontal");
private var verticalSpeed = Input.GetAxis("Vertical");

function Update()
{

	rigidbody.mass = 0.1;
	var otherScript = GetComponent(FPSWalker);

}

function OnControllerColliderHit (collisionObject: ControllerColliderHit)
{ 
	if(collisionObject.gameObject.name == "Fire"  Time.time > nextActivationTime) 
	{ 
		
		nextActivationTime = Time.time + speedBoostDuration;
		
		for (var i = 0; i <= 6; i++)
		{
			temporarySpeed = otherScript.speed +increase;
			yield WaitForSeconds(5);
		}
		rigidbody.AddTorque(Vector3(0,horizontalSpeed,verticalSpeed) * 10); 
		rigidbody.AddForce (Vector3(temporarySpeed,0,0));
		
		Destroy(gameObject); 
	} 
	
	else
	{
		return otherScript.speed;
	}

}

Thank you in advance! :slight_smile:

You are attempting to return otherScript.speed from the OnControllerColliderHit function but this function shouldn’t have any return value. As regards the timing, the approach you are using seems OK so this should work when you get rid of the compile error.

Oh okay. Thank you so much! I managed to solve the problem. Your advice helped me a lot! Thanks!!

Another question. I have changed the statment “Destroy(gameObject);” to “Destroy(Fire, 0.0);” as my FPS disappears when it touches a fire orb. I have more than 1 fire orb. But I can only assign one fire orb to the variable Fire in the Inspector. Thus whenever my FPS hit another fire orb, the orb that is hit will not disappear and the orb that is assigned to the inspector does. Erm. Is there a way whereby my FPS will be able to go through a specific fire orb and that specific fire orb will be destroyed despite having many fire orbs around?