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 JuanseCoello · Jul 27, 2013 at 02:14 AM · inputjumpnot workingdelay

Coroutine doesnt work. Delayed Jump.

I am making my character Move and Jump. But I want to add a coroutine to the Jump, It has two jumps, Jump2() works fine, but the coroutine is not recognized. Why? Here is the code:

using UnityEngine; using System.Collections;

public class TP_Controller : MonoBehaviour {

 public static CharacterController CharacterController;
 public static TP_Controller Instance;

 void Awake() 
 {
     CharacterController = GetComponent("CharacterController") as CharacterController;
     Instance = this;
 }
 

 void Update() 
 {
     GetLocomotionInput();

     HandleActionInput();

     TP_Motor.Instance.UpdateMotor();

     DelayedJump(); 

 }

 void GetLocomotionInput()
 {
     var deadZone = 0.1f;

     TP_Motor.Instance.VerticalVelocity = TP_Motor.Instance.MoveVector.y;

     TP_Motor.Instance.MoveVector = Vector3.zero;

     if (((Input.GetAxis("Vertical") > deadZone) && !Input.GetKey(KeyCode.LeftShift)) ||
         (Input.GetAxis("Vertical") < -deadZone && !Input.GetKey(KeyCode.LeftShift)))
         TP_Motor.Instance.MoveVector += new Vector3(0, 0, Input.GetAxis("Vertical"));   // Moves the character vertically

     if (Input.GetKey(KeyCode.LeftShift) & Input.GetKey("d"))
         TP_Motor.Instance.MoveVector += new Vector3(Input.GetAxis("Horizontal"), 0, 0);  // Makes the character strafe Right

     if (Input.GetKey(KeyCode.LeftShift) & Input.GetKey("a"))
         TP_Motor.Instance.MoveVector += new Vector3(Input.GetAxis("Horizontal"), 0, 0);  // Makes the character strafe Left

     if (((Input.GetAxis("Horizontal") > deadZone) && !Input.GetKey(KeyCode.LeftShift)) ||
         (Input.GetAxis("Horizontal") < -deadZone) && !Input.GetKey(KeyCode.LeftShift))
        transform.Rotate (0, Input.GetAxis("Horizontal"), 0);  // Makes the character rotate around its axis.


     TP_Animator.Instance.DetermineCurrentMoveDirection();

 }

 void HandleActionInput()  // Makes the character Jump
 {

     if (Input.GetKey(KeyCode.Space))
     {
         StartCoroutine(DelayedJump());
     }

     else if (Input.GetKey("w") && !Input.GetKey(KeyCode.LeftShift) ||
         (Input.GetKey("up")) && !Input.GetKey(KeyCode.LeftShift))
     {
         Jump2();
     }
 }

 IEnumerator DelayedJump () 
 {
     yield return new WaitForSeconds(0.5f);
     TP_Motor.Instance.Jump();
 }

 void Jump2()
 {
     TP_Motor.Instance.Jump2();
 }

}

I have another TP_Motor script where the jump is called.

Comment
Add comment · Show 1
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
avatar image SolidSnake · Jul 29, 2013 at 05:33 PM 0
Share

why are you calling DelayedJump() inside Update()?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ScottYann · Aug 03, 2013 at 11:58 PM

You have to call your coroutine like this:

StartCoroutine(DelayedJump());

Otherwise exec will skip over it entirely and not even give you an error. Frustrating isn't it :D

Comment
Add comment · Show 2 · 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
avatar image JuanseCoello · Aug 08, 2013 at 11:34 PM 0
Share

Thanks but I have already done that, check the code. Or am I doing something bad ins$$anonymous$$d???

avatar image ScottYann · Aug 09, 2013 at 01:03 AM 0
Share

In your code you have this:

void Update() { GetLocomotionInput();

HandleActionInput();

TP_$$anonymous$$otor.Instance.Update$$anonymous$$otor();

DelayedJump();

}

//delayed jump is in there without it being started as a coroutine... thats where my eye first fell

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

17 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Delay jump to confirm player really wants to jump 1 Answer

I Watched The Unity New Ball Rolling Game Tut, How I Can Make Jump,I Watched The New Unity Ball Rolling Tutorial, How I Can Make Jump? 0 Answers

Using a touch event for character motor 0 Answers

jumping and landing not very responsive 1 Answer

Access to float seconds ago 2 Answers


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