Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ryno9788 · Jan 27, 2013 at 02:54 AM · c#ienumeratoryield waitforseconds

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 forUnityEngine.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 
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges