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!