- Home /
sprint timer
okay my game is an rpgfps game. so I need help cleaning up my script for my controller. I plan to do this one question at a time so I won't be too vague. Firstly I'v now translated my script to c# and am getting a ton of compiler errors.
(And not to advertise so much but this is part of my open project : project VC anyone who wants to contribute can)
(119,37): error CS1503: Argument #1' cannot convert
double' expression to type float' (119,37): error CS1502: The best overloaded method match for
UnityEngine.WaitForSeconds.WaitForSeconds(float)' has some invalid arguments (121,1): error CS0103: The name `sprintTimer' does not exist in the current context
I picked these specifically because they seem they may be some of the main problem my largest problem is anything with yield because it is one of the main things I don't know much about in c# and i don't even know whats wrong with the sprint timer
i now my script is long put i can't even begin to figure out whats wrong with it
void Update(){
transform.Rotate(0,Input.GetAxis("Mouse X") * rotateSpeed * Time.deltaTime, 0);
if(!swiming){
//if (Input.GetButtonUp("Fire2")){
if (Input.GetKeyUp("left shift")){
sprintControl();
}}
//if (Input.GetButton("Fire2")){
if(!swiming){
if (Input.GetKey("left shift")){
if(!isCoolingDown){
if (currentSpeed <= maxSpeed){
currentSpeed++;
}
else {
if(Input.GetAxis("Vertical")){
animation.Play("walk");
sprintControl();
}
}
}
}}
}
void FixedUpdate() {
if (Input.GetKeyDown("q")){
//moveDirection.y = jumpSpeed;
animation.Play("roll");
//Roll();
}
if(allowMove){
if (grounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= currentSpeed;
if(!swiming){
if (Input.GetButton("Jump")) {
moveDirection.y = jumpSpeed;
//Roll();
}
if (Input.GetKeyDown("q")) {
//animation.CrossFade("roll");
moveDirection.y = jumpSpeed;
Roll();
}
}
}
else if (climbing){
moveDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"),0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= currentSpeed;
}
}
if(swiming){
currentSpeed = walkSpeed;
//isCoolingDown = true;
if(Input.GetAxis("Vertical")){
animation.Play("walk");
}
}
else{
isCoolingDown = false;
}
moveDirection.y -= gravity * Time.deltaTime;
CharacterController controller = GetComponent(CharacterController);//over load
float flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
controller.Move(moveDirection * Time.deltaTime);
}
//this will tell what to do when you've sprinted longer sprintStamina
void sprintControl(){
if(!swiming){
sprintTimer += Time.deltaTime;//this is were the sprint timer is used
if(sprintTimer > sprintStamina){
StartCoroutine(dothis());
}}}
//this was newly added to make you slowdown and i believe this is where te overload error is
IEnumerator dothis (){
currentSpeed = walkSpeed;
isCoolingDown = true;
yield return new WaitForSeconds(8.0);
isCoolingDown = false;
sprintTimer = 0.0;
}
//place my other junk here
Answer by iwaldrop · Jan 27, 2013 at 03:20 AM
In C# a coroutine method must have a return type of IEnumerator. Also, to start one you must call it with a StartCoroutine method.
http://docs.unity3d.com/Documentation/ScriptReference/index.Coroutines_26_Yield.html
Your answer
Follow this Question
Related Questions
IEnumerator's did not read "bool" after yield return new WaitForSeconds. 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
how to yield in C# 1 Answer
Proper Way to Wait in C# 1 Answer